Json-server Usage Summary
What: Forge Online rest APIs, provide virtual data to front-end pages, support Cors and JSONP cross-domain requests, support get, POST, PUT, PATCH, and DELETE methods
How-to-use method one: Call online using an on-line address
After entering the online address http://jsonplaceholder.typicode.com/, a variety of analog data interfaces are available at the bottom of the page for us to call directly
, the fields in the interface and the data structures are fixed, and we can't change them to fit our scenario, so we can use Json-server to simulate the data locally and write the JSON file according to our own needs.
Use method Two: Use Json-server local call
First, the global installation: in the installation of Nodejs premise, open the terminal, the global installation Json-server
NPM install-g Json-server
Second, initialize: Create a new Folder project and CD into project, initialize the Package.json file
NPM Init
Third, confirm package information: Enter to confirm name,version and so on, generate Package.json file
Four, install Json-server module, after success, Package.json will display the version number
NPM Install Json-server--save
V. Create Data.json in folder project and write JSON data as needed
Vi. monitoring Data.json files, "My-server" for custom names
Seven, the address below the start Json:my-server,resource is the generated local interface address
NPM Run Json:my-server
Eight, in addition to their own local simulation JSON data, you can also remotely introduce Jsonplaceholder data
Nine, if the interface address too many, you can create a new Readme.txt, copy it for inspection
Ten, when the interface data returned too much, inconvenient to consult, can use postman consult
Json-server Usage Summary