安装json-server
npm install -g json-server
jsoin-server基本用法
json-server [options] <source>
Options:
--config, -c json-server配置文件,默认[json-server.json]
--port, -p 配置接口,默认[3000]
--host, -H 配置host,默认[0.0.0.0]
--watch, -w 伪接口调用的文件
--routes, -r 配置伪接口路由文件
--help, -h
--version, -v
Example 简单例子
创建一个db.json文件
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
启动json 服务
json-server –watch db.json
请求执行,默认为3000端口 http://localhost:3000/posts/1
{ "id": 1, "title": "json-server", "author": "typicode" }
更多详情请访问json-server