JSON-Server 介绍
环境 ?
需要安装node
开始 ?
1.新建项目 mkdir rest-api-demo && cd rest-api-demo
2.初始化项目 npm init
3.安装 npm install --save-dev json-server
4.在项目根目录下,新建 一个 jsON 文件 db.json
{
"posts": [
{ "id": 1,"title": "json-server","author": "typicode" }
],
"comments": [
{ "id": 1,"body": "some comment","postId": 1 }
],
"profile": { "name": "typicode" }
}
5.打开 package.json,在 scripts 字段 添加 一行
"scripts": {
"server": "json-server db.json",// 新加行
"test": "..."
}
6.启动服务npm run server
{^_^}/ hi!
Loading db.json
Done
Resources
http://localhost:3000/posts
http://localhost:3000/comments
http://localhost:3000/profile
网站地址 : https://www.npmjs.com/package/json-server
GitHub: https://github.com/typicode/json-server
网站描述: 用于搭建一台JSON服务器,测试一些业务逻辑
JSON-Server官方网站
官方网站: https://www.npmjs.com/package/json-server
如果觉得 网站内容还不错,欢迎将 网站 推荐给程序员好友。