19_mock.js

官网

https://www.npmjs.com/package/json-server#getting-started

1 全局安装json-server

  • npm install -g json-server

2 创建json文件存储数据

// 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值