Your First Mock

Creating an API Mock is simple and straightforward. Basic hierarchy of data that you need to create for an API mock is API > Route > Response. To get started, you first need to create an API.

API


API is the foundation of your mock, it’s the top level entity and it has properties such as Name, Description, URL and Authorization Regex. The URL you enter here will be a suffix value that will have a dash and 6 random characters appended to it. Authorization Regex serves as a check for accessing your mock using the Authorization Header.

You can create an API on the APIs page by clicking on the Create a new API button. Fill all of the necessary data (Name, Description and URL) and your API will be created and visible to the internet. Authorization Regex field is used to protect your API by requiring all requests to pass along an Authorization header with a value that you define with this field using regex. You can visit the newly created API by using the URL from the next page as the subdomain (example: companyname-jioqkw.mockadillo.com).

Route


Route is the next unit of your mock and you will be forwarded to the Routes page automatically upon creating your first API. Depending of what you’re trying to accomplish it can represent an HTML page, a REST entity, an RPC method, or anything you want it to be. It has properties such as Name, Description, Method, URL and Authorization Regex. Authorization Regex is the same as for the API, but gives you fine grained control where you can have protected and unprotected routes. URL represents the route URL that will be the endpoint for the request.

Once on the Routes page you will be able to create Routes for your API. Every route URL and Method combination should be unique for the API otherwise you may face inconsistent behavior. Click on the Create a new route button, fill all of the required fields (all other than Authorization Regex, which provides you a more fine grained control over required authorization) and click on Save. Upon creating a new route you will be redirected to it’s page.

Response


On the Route page you can manipulate responses for the given route. A Response is the last unit of your mock. It is the actual thing that you receive when you request an endpoint. It has properties such as Name, Status Code, Conditions, Headers, Response and Response Latency. Conditions is the place to define prerequisites for the response. You can define Header, Body and Origin conditions. As of this moment we implement a system that will return the response with the most conditions fulfilled. If you want to read more you can do so here. Response field represents the raw response body that will be returned. As of right now we are optimized for JSON, but in the near future we plan on allowing you to return any kind of a response, including base64 encoded binaries. Response Latency represents the minimal time in milliseconds before a response will be returned from the server. You can use this to your advantage to simulate delayed responses.

Click on the Create a new response button, fill all of the required fields (only Name and Status) and data that you want to be returned. Here you are presented with more options than for API and Route, we recommend that you define this as your default Response for this route. Default responses are returned when no other response can be resolved for the given Request data using Conditions. You can read more about Responses here. Click on Save to save your response. Once your response is saved you can now visit the newly created response by visiting yourapiurl-suffix.mockadillo.com/routeURL with the appropriate method and you should see your response!

Congrats on creating your first Mock. You can point your code to target the newly created route and continue working on that UI worry free!