To call a REST API, the Client Application has to construct an HTTP Request. The http request has to constructed according to the specifications or the API Server will fail to understand Client's request.
When creating a new mock API endpoint, an important step is to define how the the HTTP Request looks like.
ApiOnCloud's API editor divides the HTTP request into 4 components:
Headers, Query Parameters and Request Body are optional. A mock API endpoint can be created with or without them.
However, every mock API endpoint must have a Path defined
The Path can be defined by entering a value in API Path text field, see an example below
Click here for more information on API Path text field
Headers for the Request can be defined using the Set HTTP Request Header(s) panel. Defining headers are optional.
The Request Headers panel is divided into 3 sections:
Pick one of the two options provided in this list. The two options are EXACT and ANY
EXACT: When "exact" is picked then the defined API will expect the request to have exactly the same header value
ANY: When "any" is picked then the defined API will not verify that the header value received from the Client Application is the same value provided in the Editor.
If headers match type is EXACT and
Header Name equals token and
Header Value equals somerandontoken
then the http request must have a header named token and its value must be somerandomtoken. Otherwise, the client application will not receive any response back from the ApiOnCloud's mock API server
If headers match type is ANY and
Header Name equals token and
Header Value equals somerandomtoken
then the http request must have a header named token but the value of the header can be anything. The header token can have a value of 1 or abc or somerandomtoken or anyotherrandomstring
Query Parameters can be defined using the Set Request Query Parameter(s) panel. Defining query parameter(s) is optional.
The Query Parameters panel is divided into 3 components
Pick one of the two options available in this list. The two options are EXACT and ANY
EXACT: When "exact" is picked then HTTP Requests must have the exact same query parameter Keys and Values
ANY: When "any" is selected then HTTP Requests must have the same query parameter Keys. Values for the parameter keys can be any string such as: abc, xyz, 123, somerandomparametervalue
If Query Parameters Match Type equals exact and
Query Parameter Key equals min-price and
Query Parameter Value equals 15
then the HTTP Request must contain a query parameter named min-price and its value must be 15. Otherwise, no response will be received from ApiOnCloud's mock API server
If Query Parameters Match Type equals any and
Query Parameter Key equals min-price and
Query Parameter Value equals 15
then the HTTP Request must contain a query parameter named min-price but its value can be any string such as: 15 or abc or some-other-random string. Otherwise, no response will be received from ApiOnCloud's mock API server
A request body can be provided for HTTP Post and HTTP Put requests. To specify the contents of the request body, select the checkbox displayed on the screen
Additional fields are displayed upon checking the checkbox. Contents of the request body can be specified in the additional fields. The additional fields are:
HTTP POST and HTTP PUT APIs with request body cannot be saved without specifying the Content-Type. Some examples of Content-Type are:
A value must be picked from this list before saving HTTP POST or HTTP PUT requests with a body. The two options are exact and any.
If Content-Type is application/json and
Match Type is exact and
Request Body contains { "City": "New York", "State": "New York" }
then the Calling Application must have Content-Type header set to application/json and request body must equal { "City": "New York", "State": "New York" }.
No response will be returned by ApiOnCloud's mock API server if the json doesn't match
If Content-Type is application/json and
Match Type is any and
Request Body contains { "City": "New York", "State": "New York" }
then the Calling Application must have Content-Type header set to application/json but the request body can contain any valid json, such as:
{ "City": "New York", "State": "New York" }
OR
{ "City": "Los Angeles", "State": "California" }
OR
{ "Name": "John Smith", "identifier": "112233" }