- API Client makes a request to Apinizer.
- Apinizer makes a request to Cars Mock API.
- The tip, yıl, fiyat keys in the response returned from Cars Mock API are converted to type, year, price key expressions by applying the JSON Transformation policy and transmitted to Apinizer.
- The operation of the Script policy is optional. Because this policy works if there is any Order By parameter in the request coming from the API Client.
- Response is given from Apinizer to API Client.

Creating Mock API
First, the design of the Mock API to be requested is performed. For this, the Mock API option found in the API Creator menu under the Development menu is selected.

- There are two different options for creating Mock API.
- When the Blank expression is selected, Name and Description expressions are present.
- The API’s name is determined with the Name field.
- Descriptions for this API can be written with the Description expression.
- With the Generate Crud Operations expression, it is specified that GET, POST, DELETE, PUT operations will come ready in the Mock API to be created.

- If the Import Spec option is selected, the page will be created as in the image below.
- With this expression, an existing API can be included in Apinizer.
- The options under the API Spec Type expression specify what type the API to be added is.
- Import Type specifies how the addition operation will be performed.

- The name and description information belonging to the API is seen in the Definition - API Information field.
- In the API Endpoints -Endpoints of the API field, the endpoints that the Mock API has are located.
- A new endpoint can be added with the Add button found in this field, or changes can be made on existing endpoints by selecting them.

In this scenario, tests will be performed through an endpoint named “/getCarList” of type “GET”.
- The type of endpoint to be created is determined with the HTTP Method field.
- The endpoint’s name is specified in the field right next to it.
- A description can be added to this endpoint with the Description expression.
- The responses to be received when a request is made are determined with the Response Information - Enter Response Details field.
- New responses can also be created with the button containing ”+” in this field.
- In this scenario, a response design that only returns “200” response will be performed.
- The button containing a pencil icon enables editing operations of the relevant response to be returned.

- The response to be received when making a request to the endpoint is specified in Response Body.
- A list with type, year, and price is found in this field.
- The type of response to be returned is determined with the Status Code field, and the type of content to be returned is determined with the Response Content Type field.
- If a Headers parameter will be sent in the response, it is specified in the Headers field.
- If a condition is desired to be created in this response, a rule definition can be made from the Condition field.
- After these changes, click the Edit button to save the edits.


Creating API Proxy from Mock API
The proxy’s usage and category are determined. A suitable Relative Path is given to the proxy and the Save button in the top right corner is clicked.


In the first test to be performed, no policy application will be made in any way.

Adding JSON Transformation Policy
A policy must be added to enable the key expressions in the scenario to change. This policy will be in the field that will go as a response from the API to the Client. Click the Add Policy expression in the field seen in the image below.

- A description can be added to the policy to be used with the Description field.
- The Jolt Value required for the message to be changed is written with the Configuration - Enter the policy configurations field.
- The written configuration is tested with the Test Jolt expression.
- The created policy is saved by clicking the Save button.
- Click the Redeploy button for the changes to take effect.
- Proceed to testing the selected endpoint.


Adding Script Policy
Next is the execution of the script that will sort according to the “Order By” parameter value to be sent from the client. For this, the Script policy must be added to the field where the response sent from Mock API to the client is located. Click the Add Policy expression and select the Script policy from here.
- The programming language with which the Script to be created will be written is selected with the Script Language field.
- The Script Body field contains both the field where the script will be written and ready functions that facilitate use when writing scripts.
- In this scenario, the function named ResponseBodyTextToClient will be used.
- To get information about other ready functions, you can click this link.
- After writing the script to be used, click the Save button and the policy is saved.


Testing the API Proxy
Click the Test Endpoint expression. In the first test, no query parameters are sent to the mock API and the answer in the “Response” field is obtained.



