1) Create a folder on Desktop or Any other place ex. users-api-server
2) Open Terminal and Go to the folder directory . ex. cd /Users/apple/Desktop/users-api-server
3) Init npm . " npm init -y "
4) Install JSON-SERVER. "npm i -g json-server"
5) Create "package.json" file into folder. ex users-api-server/package.json
{
"name": "users-api-server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
“json:server”:”json-server — watch db.json”
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"json-server": "^0.16.3"
}
}
6) Create "users.json" file into flder. ex users-api-server/users.json
{
"users": [
{
"id": 1,
"first_name": "Robert",
"last_name": "Schwartz",
"email": "rob23@gmail.com"
},
{
"id": 2,
"first_name": "Lucy",
"last_name": "Ballmer",
"email": "lucyb56@gmail.com"
},
{
"id": 3,
"first_name": "Anna",
"last_name": "Smith",
"email": "annasmith23@gmail.com"
},
{
"id": 4,
"first_name": "Robert",
"last_name": "Brown",
"email": "bobbrown432@yahoo.com"
},
{
"id": 5,
"first_name": "Roger",
"last_name": "Bacon",
"email": "rogerbacon12@yahoo.com"
}
]
}
users-api-server folder should be look like following way
7) Then start server. Go to the users-api-server folder on terminAL ex. cd /Users/apple/Desktop/users-api-server
The "json-server --watch users.json ". Then mock api server will start
output like below
Demo through POSTMAN
Demo through IDE ( IntelliJ )
If you are not start json server and try to execute api . Then you will get following error