JsonServer
The main role is to build local data interface, create json file for easy debugging calls
Node is a module, running Express server, you can specify a file as json api data source
Official website: https://www.npmjs.com/package/json-server
Global json-server installation
Terminal type: NPM the install -g JSON-Server (Windows system)
mac system: compared sudo npm install -g json-server as shown below:
Initialization package.json
Terminal to the directory you want to store the file
Perform the initialization command: npm the init
To package a name, you can enter other default
jsonserver saved locally
Execute the command: npm install json-Server --save
After executing the file open package.json
The scripts modify the contents:
Use json-server when most start: "server json"
db.json will be used as a start as the data server
Create a file db.json
Creating db.json file in the same directory with the package.json, and populate the data in the format object
Run json-server
Terminal type: NPM JSON RUN: Server
FIG as: home address: HTTP: // localhost: 3000
resources 地址,即创建的db.json中数据所在位置:http://localhost:3000/product
浏览器中运行 http://localhost:3000 后:
浏览器中运行 http://localhost:3000/product 后结果:
如下图,浏览器中每访问一次,终端则会输出对应的执行
postman 请求该接口
通过postman 请求该 API 发现数据确实来源于服务端