30秒内无需编码快速完成一个模拟的REST API服务。前端
这个服务主要是给那些须要快速的模拟原型后端接口的前端人员使用的git
GitHub:https://github.com/typicode/j...github
$ npm install -g json-server
新建一个 db.json 文件npm
{ "posts": [ { "id": 1, "title": "json-server", "author": "lucy" } ], "comments": [ { "id": 1, "body": "some comment", "postId": 1 } ], "profile": { "name": "typicode" } }
$ json-server --watch db.json
到这一步30秒不到吧,一个完整的rest api 就基本完成了。json
ok,如今直接在浏览器打开http://localhost:3000/posts/,你便能看到数据返回后端
{ "id": 1, "title": "json-server", "author": "lucy" }
{"name": "lucy"}
Content-Type: application/json
了解以上须要注意的地方后就能够像正常的rest api 同样去调用了api
这里的id不须要手动赋值,程序会自动递增。浏览器
其它的能够使用postman来测试请求,反正很方便就对了bash
固然还有其余更强大的功能如分页,排序,多条件查询,模糊查询等等。均可以直接查看官方文档:https://github.com/typicode/j...app