Getting started
- Create a db.json file with some data(创建de.json)
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
json-server --watch db.json
{ "id": 1, "title": "json-server", "author": "typicode" }
- If you make POST, PUT, PATCH or DELETE requests, changes will be automatically and safely saved to db.json using lowdb.(使用 lowdb 数据库保存被修改的JSON数据)
- Id values are not mutable.(id不可修改)
- Any id value in the body of your PUT or PATCH request will be ignored. (被忽略)
- Only a value set in a POST request will be respected, but only if not already taken.(未引用可被POST请求设置?)
- A POST, PUT or PATCH request should include a Content-Type: application/json header to use the JSON in the request body. (修改请求传输 JSON body 时需要设置头部 Content-Type: application/json)
- Otherwise it will result in a 200 OK but without changes being made to the data.(否则将返回200但是未修改数据)
——————————————————————————————————————————————————————————————
Routes
Plural routes
Singular routes
Filter
Paginate
Sort
Slice
Operators
Full-text search
Relationships
Database
Homepage
——————————————————————————————————————————————————————————————
Static file server
Alternative port
Access from anywhere
Remote schema
Generate random data
HTTPS
Add custom routes
Add middlewares
CLI usage
Module
Simple example
Custom routes example
Access control example
Custom output example
Rewriter example
Mounting JSON Server on another endpoint example
API
Deployment
——————————————————————————————————————————————————————————————
Links
Video
Articles
——————————————————————————————————————————————————————————————
License