Important
Enhanced JSON Server with nested routes support - A powerful REST API server for prototyping and development
A feature-rich JSON server that extends the original json-server with advanced nested routing capabilities, built by @paristech.
- Full REST API - All standard HTTP methods (GET, POST, PUT, PATCH, DELETE)
- Nested Routes - Access and modify nested resources within main resources
- Automatic ID Generation - Unique IDs for all resources
- Query Parameters - Filtering, sorting, pagination, and embedding
- Static File Serving - Serve static files alongside your API
- CORS Support - Built-in CORS handling
- TypeScript Support - Full type definitions included
- Real-time Updates - Automatic database persistence
npm install @paristech/json-serverCreate a db.json file:
{
"surveys": [
{
"id": "123",
"title": "Customer Satisfaction Survey",
"design": {
"theme": "modern",
"colors": {
"primary": "#007bff",
"secondary": "#6c757d"
}
},
"questions": [
{
"id": "q1",
"text": "How satisfied are you?",
"type": "rating"
}
]
}
]
}Start the server:
npx @paristech/json-server db.jsonBased on your db.json, you get these standard routes:
GET /surveys
GET /surveys/:id
POST /surveys
PUT /surveys/:id
PATCH /surveys/:id
DELETE /surveys/:id
The enhanced feature that sets this server apart! Access and modify nested resources within your main resources.
GET /surveys/123/design
POST /surveys/123/design
PUT /surveys/123/design
PATCH /surveys/123/design
DELETE /surveys/123/design
GET /surveys/123/questions
POST /surveys/123/questions
PUT /surveys/123/questions
PATCH /surveys/123/questions
DELETE /surveys/123/questions
GET /surveys/123/questions/q1
PUT /surveys/123/questions/q1
PATCH /surveys/123/questions/q1
DELETE /surveys/123/questions/q1
# Get survey 123's design
GET /surveys/123/design
# Update the design theme
PATCH /surveys/123/design
{"theme": "dark"}
# Add a new question
POST /surveys/123/questions
{"text": "New question?", "type": "text"}
# Update a specific question
PATCH /surveys/123/questions/q1
{"required": true}
# Replace entire design
PUT /surveys/123/design
{"theme": "colorful", "colors": {...}}→==lt→<lte→<=gt→>gte→>=ne→!=
GET /surveys?title_contains=Customer
GET /surveys?created_at_gt=2024-01-01GET /surveys?_page=1&_per_page=25
GET /surveys?_start=10&_end=20
GET /surveys?_start=10&_limit=10GET /surveys?_sort=id,-created_at
GET /surveys?_sort=title,viewsGET /surveys?_embed=questions
GET /questions?_embed=surveyGET /surveys?design.theme=modern
GET /surveys?questions.type=rating# Delete a survey
DELETE /surveys/123
# Delete with dependent cleanup
DELETE /surveys/123?_dependent=questionsCreate a ./public directory to serve static files alongside your API:
json-server -s ./static db.json
json-server -s ./static -s ./node_modules db.jsonnpx @paristech/json-server --helpCommon options:
-p, --port- Set port (default: 3000)-H, --host- Set host (default: localhost)-s, --static- Serve static files from directory--delay- Add delay to responses (useful for testing)
@paristech/json-server/
├── lib/ # Compiled JavaScript
├── examples/ # Example databases
├── views/ # HTML templates
├── package.json # Dependencies and scripts
└── README.md # This file
Check out the examples/ directory for sample databases and use cases:
# Run with example database
npx @paristech/json-server examples/nested-routes-example.json# Install dependencies
npm install
# Run in development mode
npm run dev
# Build for production
npm run buildGET /:resource- List all itemsGET /:resource/:id- Get specific itemPOST /:resource- Create new itemPUT /:resource/:id- Replace itemPATCH /:resource/:id- Update itemDELETE /:resource/:id- Delete item
GET /:resource/:id/:nested- Get nested resourcePOST /:resource/:id/:nested- Add to nested resourcePUT /:resource/:id/:nested- Replace nested resourcePATCH /:resource/:id/:nested- Update nested resourceDELETE /:resource/:id/:nested- Remove nested resource
GET /:resource/:id/:nested/:nestedId- Get specific nested itemPUT /:resource/:id/:nested/:nestedId- Replace specific nested itemPATCH /:resource/:id/:nested/:nestedId- Update specific nested itemDELETE /:resource/:id/:nested/:nestedId- Remove specific nested item
This project is maintained by @paristech. Contributions are welcome!
This project is licensed under the terms specified in the LICENSE file.
Built on top of the excellent json-server by typicode, enhanced with nested routing capabilities.
Built with ❤️ by @paristech