Skip to content

API Reference

mocks automatically generates RESTful API endpoints based on the structure of JSON files. All endpoints send and receive data with Content-Type: application/json.

For resources defined as arrays (e.g., posts, comments), the following endpoints are generated:

MethodPathDescription
GET/{resource}Get all items
GET/{resource}?{query}Get items based on search criteria
GET/{resource}/{id}Get specific item
POST/{resource}Create new item
PUT/{resource}/{id}Replace existing item completely
PATCH/{resource}/{id}Update existing item partially
DELETE/{resource}/{id}Delete existing item

For resources defined as objects (e.g., profile), the following endpoints are generated:

MethodPathDescription
GET/{resource}Get object
PUT/{resource}Replace object completely
PATCH/{resource}Update object partially

For array-type resources, you can use query parameters for searching.

{field}.{matchtype}={value}
Match TypeDescriptionExample
exactExact match (case-insensitive)title.exact=Hello
containsPartial match (case-insensitive)title.contains=world
startswithPrefix match (case-insensitive)title.startswith=Hello
endswithSuffix match (case-insensitive)title.endswith=World
  • Search is only available for array resource listing (GET /{resource})
  • Cannot be used for single item retrieval (GET /{resource}/{id})
  • Complex values (objects or arrays) cannot be searched
  • Match type is required (formats like field=value are not allowed)

When combining multiple search conditions, they are joined with AND logic:

Terminal window
curl "http://localhost:3000/posts?title.contains=post&views.exact=100"
Status CodeDescription
200 OKRequest completed successfully
201 CreatedNew resource created
204 No ContentRequest completed successfully (no response body)
400 Bad RequestInvalid request
404 Not FoundSpecified resource not found
405 Method Not AllowedUnsupported HTTP method
500 Internal Server ErrorServer internal error
GET /_hc

Endpoint for checking server status. Always returns 204 No Content.

Options available when starting the mocks server:

OptionShortDefaultDescription
--host-HlocalhostHost address to bind to
--port-p3000Port number to bind to
--no-overwritenonefalsePrevent overwriting original JSON file
--help-hnoneDisplay help message
--version-VnoneDisplay version information
  • Resource names must be unique (cannot coexist api/v1/users and api/v2/users)
  • Each item in array resources needs a unique ID
  • JSON file changes are automatically saved to the original file (can be disabled with --no-overwrite option)

By setting the MOCKS_DEBUG_OVERWRITTEN_FILE environment variable, you can save modified data to a separate file:

Terminal window
MOCKS_DEBUG_OVERWRITTEN_FILE=storage.debug.json mocks run storage.json

This feature is useful for debugging during development.