内容纲要

https://github.com/typicode/json-server

[code]
npm install -g json-server
[/code]

[code]
mkdir json-server
cd json-server
touch db.json
[/code]

db.json
[code language=”js”]
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
[/code]

[code]
$ json-server –watch db.json
[/code]

http://localhost:3000
http://localhost:3000/posts/1

[code]
GET /posts
GET /posts/1
POST /posts
PUT /posts/1
PATCH /posts/1
DELETE /posts/1
[/code]

过滤器,使用 . 访问深度属性
[code]
GET /posts?title=json-server&author=typicode
GET /posts?id=1&id=2
GET /comments?author.name=typicode
[/code]

分页
[code]
GET /posts?_page=7
GET /posts?_page=7&_limit=20
[/code]

发表评论

电子邮件地址不会被公开。 必填项已用*标注