Package Exports
- json-server/package.json
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-server) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
json-server
Install
npm install json-server@alphaUsage
Create a db.json or db.json5 file
{
"posts": [
{ "id": "1", "title": "a title" },
{ "id": "2", "title": "another title" }
],
"comments": [
{ "id": "1", "text": "a comment about post 1", "postId": "1" },
{ "id": "2", "text": "another comment about post 1", "postId": "1" }
]
}Pass it to JSON Server CLI
json-server db.jsonGet a REST API
curl -H "Accept: application/json" -X GET http://localhost:3000/posts/1
{
"id": "1",
"title": "a title"
}Run json-server --help for a list of options
Routes
GET /posts
GET /posts/:id
POST /posts
PUT /posts/:id
PATCH /posts/:id
DELETE /posts/:idParams
Comparison
→==lt→<lte→<=gt→>gte→>=ne→!=
GET /posts?views_gt=9000Range
startendlimit
GET /posts?_start=10&_end=20
GET /posts?_start=10&_limit=10Paginate
pageper_page(default = 10)
GET /posts?_page=1&_per_page=25Sort
_sort=f1,f2
GET /posts?_sort=id,-viewsNested fields
x.y.z
Include
GET /posts?_include=comments
GET /comments?_include=postDelete
DELETE /posts/1
DELETE /posts/1?_include=commentsServing static files
If you create a ./public directory, JSON Serve will serve its content in addition to the REST API. You can add custom directories using -s/--static option.
json-server -s ./static
json-server -s ./static -s ./node_modulesLicense
This project uses the Fair Source License. Note: Only organizations with 3+ users need to contribute a small amount through sponsorship sponsor for usage. This license helps keep the project sustainable and healthy, benefiting everyone.
For more information, FAQs, and the rationale behind this, visit https://fair.io/.