Mock API allows to simulate the behavior of a real API.

When we make an HTTP call to the endpoint we created without any software development, a prespecified response is returned.

In this content, creating an empty Mock API, returning a response from the endpoint according to the condition, and creating and installing and testing the API as API Proxy will be explained, respectively.

Thanks to the conditions added to the response, Apinizer ensures that different responses are received based on the header, body or parameter values of the request.

1. Creating Mock API

It is desired to create an API where worker records are managed.

Since the enpoint and response information of the API will be created through the interface instead of the API definition document, the Blank option is selected as the type.

By default, the API's feature of creating enpoints of CRUD operations is enabled.

The name and description fields of the Mock API are filled and the Save and Next button is clicked.

The picture below shows the Mock API settings:


When Mock API is created, API and enpoint information are on the right panel, and endpoint definitions are on the right.


2. Return Different Response Based on Condition

When a request is sent to /get enpoint by default (no condition defined), it is aimed to return a successful status code and the entire worker list.


When the value of the username header is dwight, the following condition is created to return only this personnel's information.

 


3. Viewing API Definition Documents

In order to access the API definition files of Employee Mock API, the Show Specs link is clicked.


The picture below shows the Spec Information dialog:


4. Creating API Proxy

API Proxy can be created instantly by clicking the Create API Proxy button on the Mock API screen.


While creating the API Proxy, fill in the input fields in the image below and click the Save button.


4.1 Go Live API Proxy

Employee API Proxy can be quickly deployed on the defined environment and opened for consumption by clients.

The management of this process can be done through the dialog opened with the Deploy button on the API Proxy screen.


This process can also be managed from the Manage API Proxies link on the Mock API screen.


5. Testing

When the condition defined in the /get endpoint is sent without adding the request, the body of the response below is returned, listing all employees.


The following customized response is returned when added to the /get endpoint with the condition defined and run.