A RESTful mock server built with json-server for rapid API prototyping and testing.
npm installnpm startThis starts the server on http://localhost:3000 with live reload when db.json changes.
npm run start:customThis runs the custom server with additional middleware and routes.
npm run devThis adds a 1-second delay to all responses to simulate real network conditions.
The server provides the following REST endpoints:
GET /api/users- Get all usersGET /api/users/:id- Get user by IDPOST /api/users- Create a new userPUT /api/users/:id- Update userDELETE /api/users/:id- Delete user
GET /api/posts- Get all postsGET /api/posts/:id- Get post by IDPOST /api/posts- Create a new postPUT /api/posts/:id- Update postDELETE /api/posts/:id- Delete post
GET /api/comments- Get all commentsGET /api/comments/:id- Get comment by IDPOST /api/comments- Create a new commentPUT /api/comments/:id- Update commentDELETE /api/comments/:id- Delete comment
GET /api/products- Get all productsGET /api/products/:id- Get product by IDPOST /api/products- Create a new productPUT /api/products/:id- Update productDELETE /api/products/:id- Delete product
GET /api/health- Health check endpointGET /api/search?q=query- Search endpoint (placeholder)
json-server supports various query parameters for filtering, sorting, and pagination:
GET /api/users?role=developer
GET /api/posts?authorId=1
GET /api/products?inStock=trueGET /api/users?_sort=name&_order=asc
GET /api/posts?_sort=createdAt&_order=descGET /api/users?_page=1&_limit=10GET /api/users?q=johnGET /api/posts?_expand=user
GET /api/users?_embed=postsThe server comes with sample data including:
- Users: Developer profiles with roles and contact info
- Posts: Blog posts with authors and timestamps
- Comments: Post comments with relationships
- Products: E-commerce product catalog
- Edit
db.jsonto add new data collections - The endpoints will be automatically available
Edit server.js to add custom routes and middleware:
// Add custom routes
server.get('/api/custom-endpoint', (req, res) => {
res.json({ message: 'Custom response' });
});To reset the database to its original state:
npm run resetThis will restore db.json from the backup file.
PORT- Server port (default: 3000)
You can test the API using curl, Postman, or any HTTP client:
# Get all users
curl http://localhost:3000/api/users
# Get a specific user
curl http://localhost:3000/api/users/1
# Create a new user
curl -X POST http://localhost:3000/api/users \
-H "Content-Type: application/json" \
-d '{"name":"New User","email":"new@example.com","role":"tester"}'
# Update a user
curl -X PUT http://localhost:3000/api/users/1 \
-H "Content-Type: application/json" \
-d '{"name":"Updated Name","email":"updated@example.com","role":"senior-developer"}'
# Delete a user
curl -X DELETE http://localhost:3000/api/users/1- β Full REST API with CRUD operations
- β Automatic route generation from JSON data
- β Filtering, sorting, and pagination
- β Full-text search
- β Relationships and data expansion
- β CORS support
- β Custom middleware support
- β Hot reload during development
- β Database backup and reset functionality
Feel free to submit issues and enhancement requests!
MIT