Skip to content

Quick Start

First, create a JSON file that defines your data using the init command:

Terminal window
mocks init storage.json

This creates a storage.json file with sample data like this:

{
"posts": [
{ "id": 1, "title": "Hello World", "content": "This is a sample post" }
],
"profile": { "id": 1, "name": "Sample User" }
}

Alternatively, you can create an empty structure:

Terminal window
mocks init --empty storage.json

Which creates:

{
"posts": [],
"profile": {}
}

Launch the mock server using your JSON file:

Terminal window
mocks run storage.json

By default, the server starts at http://localhost:3000.

You can specify custom host and port:

Terminal window
mocks run -H 127.0.0.1 -p 8080 storage.json

For Docker containers or external access:

Terminal window
mocks run -H 0.0.0.0 storage.json

Once the server is running, the following endpoints are available:

Terminal window
# Get all posts
curl http://localhost:3000/posts
# Get specific post
curl http://localhost:3000/posts/1
Terminal window
curl -X POST http://localhost:3000/posts \
-H "Content-Type: application/json" \
-d '{"id": 2, "title": "New Post", "content": "This is a new post"}'
Terminal window
# Complete update (PUT)
curl -X PUT http://localhost:3000/posts/1 \
-H "Content-Type: application/json" \
-d '{"id": 1, "title": "Updated Post", "content": "This is an updated post"}'
# Partial update (PATCH)
curl -X PATCH http://localhost:3000/posts/1 \
-H "Content-Type: application/json" \
-d '{"title": "Partially Updated Post"}'
Terminal window
curl -X DELETE http://localhost:3000/posts/1

For array-type resources, you can use query parameters to search:

Terminal window
# Search posts containing "Hello" in title
curl "http://localhost:3000/posts?title.contains=Hello"
# Search posts with exact title match
curl "http://localhost:3000/posts?title.exact=Hello World"
# Multiple search conditions
curl "http://localhost:3000/posts?title.contains=Hello&id.exact=1"

Check server status using the health check endpoint:

Terminal window
curl http://localhost:3000/_hc
  • Auto-generation: Endpoints are automatically generated from JSON file structure
  • Persistence: Changes made via API are saved to the original JSON file
  • Arrays vs Objects: Array resources use GET /posts, single objects use GET /profile
  • ID Requirements: Each item in array resources needs a unique ID

Now that you understand the basics, explore the API Reference for detailed functionality or check out Examples for more complex usage scenarios.