Learn to 创建模拟 REST 服务器 locally which will 模拟在线 REST API and produce desired JSON responses online. It is very handy to have such REST APIs mocking capability for quick development time.
由于我们在node和angular开发环境中,让我们导入json服务器
依赖。
$ npm install -g json-server //Console Output C:\Users\admin\AppData\Roaming\npm\json-server -> C:\Users\admin\AppData\Roaming\npm\node_modules\json-server\bin\index.js + json-server@0.14.0 added 229 packages from 130 contributors in 24.844s
'db.json'
中并开始提供服务。 <前>{ “雇员”: [ { "id": 1, "name": "Lokesh", "status": "active" }, { "id": 2, "name": "Andy", "status": "Inactive" }, { "id": 3, "name": "Brian", "status": "active" }, { "id": 4, "name": "Charles", "status": "Inactive" } ]数据库.json
文件上提供服务。 $ json-server --watch 'E:\ngexamples\db.json' \{^_^}/ 你好! 加载 E:\ngexamples\db.json 完毕 资源 http://localhost:3000/员工 家 http://本地主机:3000 随时键入 s + enter 以创建数据库的快照 正在观看...
'http://localhost:3000/employees'
.
请注意,从 JSON 服务器提供的 REST 端点由
数据库.json
中的数据节点确定。它是如此简单和强大。
在评论部分把你的问题告诉我。
快乐学习!!
Ref: json 服务器 github 页面
地址:https://www.cundage.com/article/mock-rest-server.html