json-server是一个基于nodejs的超轻巧RESTful server,可供前端人员在后台接口还没有开发完毕的时候进行模拟开发,简单介绍一下上手步骤,更多的调用方式和使用说明参见github。
1.安装node环境。
2.安装json-server(直接安装到全局环境了,原谅我这么简单粗暴。。)
npm install json-server -g
3.新建数据文件d:\test.json
{
"posts": [
{
"id": 1,
"title": "json-server",
"author": "typicode"
}
],
"comments": [
{
"id": 1,
"body": "some comment",
"postId": 1
}
],
"profile": {
"name": "typicode"
}
}
4.启动server监听http请求
json-server --watch d:\test.json
5.测试在浏览器输入http://localhost:3000/posts/1,返回内容如下:
{
"id": 1,
"title": "json-server",
"author": "typicode"
}