REST API
Create and configure REST endpoints with support for all HTTP methods, multiple responses, template paths, and configurable response behavior.
How REST Endpoints Work
A REST endpoint in MockAPI defines a URL path and the HTTP methods it responds to. When a request arrives, MockAPI matches the path and method, selects a response configuration, generates data from the associated data model, and returns it with the configured status code.
Each endpoint can handle multiple HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS), and each method can have multiple responses with different status codes and return rates.
Creating an Endpoint
Navigate to REST Endpoints in the sidebar and click "New Endpoint".
Endpoint path
The endpoint path defines the URL clients use to access this endpoint. Paths should start with a forward slash (e.g., /users, /products, /orders).
You can create nested paths for resource hierarchies: /users/profile, /api/v1/products.
Configuring HTTP methods
Enable one or more HTTP methods for the endpoint. Each method can be independently configured with its own description and set of responses.
| Method | Typical Use |
|---|---|
| GET | Retrieve resources (list or single item) |
| POST | Create a new resource |
| PUT | Replace an entire resource |
| PATCH | Partially update a resource |
| DELETE | Delete a resource |
| HEAD | Same as GET but returns only headers (no body) |
| OPTIONS | Describe communication options for the resource |
Response Configuration
Each HTTP method can have one or more responses. A response defines:
| Field | Description |
|---|---|
| Status Code | The HTTP status code to return (e.g., 200, 201, 404, 500) |
| Model | The data model to use for generating the response body (see Data Generation) |
| Range | When enabled, returns an array of N items instead of a single object |
| Return Rate | The probability (0-100) this response is selected when there are multiple responses |
Multiple responses per method
You can configure multiple responses for the same HTTP method with different status codes and return rates. MockAPI uses the return rate to probabilistically select which response to return for each request.
For example, you could configure a GET method with:
- 200 OK with User model (return rate: 80)
- 404 Not Found with empty body (return rate: 15)
- 500 Internal Server Error with empty body (return rate: 5)
This means 80% of requests will return a successful response, 15% will return a 404, and 5% will simulate a server error. This is useful for testing error handling in your client application.
Range (array) responses
Enable Range on a response to return an array of generated objects instead of a single object. Set the range value to control how many items are returned.
{
"id": 1,
"name": "John Doe",
"email": "john@example.com"
}[
{ "id": 1, "name": "John Doe", "email": "john@example.com" },
{ "id": 2, "name": "Jane Smith", "email": "jane@example.com" },
{ "id": 3, "name": "Bob Wilson", "email": "bob@example.com" }
]Template Endpoints
Template endpoints use path parameters (denoted by curly braces) to match dynamic URL segments. This lets you create endpoints like /users/{id} that match any value in the {id} position.
Template syntax
Wrap parameter names in curly braces: {parameterName}. You can use multiple parameters in a single path:
/users/{id}matches/users/1,/users/abc/users/{userId}/posts/{postId}matches/users/5/posts/42/products/{category}/{id}matches/products/electronics/99
Matching priority
When a request arrives, MockAPI first tries to match an exact (non-template) endpoint. If no exact match is found, it checks template endpoints. This means /users/profile (exact) will take priority over /users/{id} (template).
Consuming Your REST API
To make requests to your mock REST endpoints, include your project's API key and use the endpoint path. See Authentication for all supported authentication methods.
Base URL
All REST endpoints are served from the same base URL. Prepend your endpoint path to construct the full request URL:
https://api.mockapi.comFor an endpoint path of /users, the full URL is https://api.mockapi.com/users. For template endpoints like /users/{id}, replace the parameter to get https://api.mockapi.com/users/42.
Request format
curl -H "x-api-key: YOUR_API_KEY" \
https://api.mockapi.com/userscurl -X POST \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "New User"}' \
https://api.mockapi.com/userscurl -H "x-api-key: YOUR_API_KEY" \
https://api.mockapi.com/users/42Query parameters
MockAPI supports the following query parameters for list endpoints:
| Parameter | Description | Example |
|---|---|---|
| limit / _limit | Number of items to return per page | ?limit=20 |
| page | Page number (when pagination is enabled) | ?page=2 |
The parameter names can be customized in your project's advanced settings. See Projects for pagination configuration.
Batch Operations
You can create or delete multiple endpoints at once using batch operations. This is useful when importing API definitions or cleaning up a project.
Best Practices
- Use meaningful paths: Follow REST conventions with plural nouns and resource hierarchies (e.g., /users, /users/{id}/posts).
- Add multiple responses: Use return rates to simulate both success and error scenarios during development. Test them in the API Playground.
- Use template endpoints: Create
/resources/{id}endpoints for detail views alongside collection endpoints. - Add descriptions: Document each HTTP method with a description so your team knows what each configuration does.