首页 > 其他分享 >创建一个json-server服务器

创建一个json-server服务器

时间:2022-10-25 11:36:49浏览次数:77  
标签:GET posts server json 服务器 typicode id

json-server

// db.json
{
  "posts": [
    { "id": 1, "title": "json-server", "author": "typicode" }
  ],
  "comments": [
    { "id": 1, "body": "some comment", "postId": 1 }
  ],
  "profile": { "name": "typicode" }
}
  • 3 启动json-server服务器
    json-server --watch db.json
  • 4 Restfull风格接口
    GET获取
    POST插入
    PUT更新整条数据
    PATCH部分更新
    DELETE 删除数据
    _page 页码
    _limit 每页显示数量,默认10
    GET /posts
    GET /posts/1
    POST /posts
    PUT /posts/1
    PATCH /posts/1
    DELETE /posts/1
    GET /posts?title=json-server&author=typicode
    GET /posts?id=1&id=2
    GET /comments?author.name=typicode
    GET /posts?_page=7
    GET /posts?_page=7&_limit=20

标签:GET,posts,server,json,服务器,typicode,id
From: https://www.cnblogs.com/maxiaohu/p/16824294.html

相关文章