******************************************************************************
How to Fake or Mock an API with JSON Server
******************************************************************************JSON Server is an easy and quick-to-set-up module that you can use to fake or mock an API.
Getting Started:
1. Install node.JS on your system
2. Exeute below command to install json-server globally
npm install -g json-server
Eg. C://User/json-server/db.json
4. db.json file contains below simple json, you can have any complex json in db.json file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"employees": [ | |
{ | |
"id": 1, | |
"first_name": "Tom", | |
"last_name": "vaughan", | |
"email": "Tom@everythingautomation.com" | |
}, | |
{ | |
"id": 2, | |
"first_name": "Garry", | |
"last_name": "Willingstone", | |
"email": "Garry@everythingautomation.com" | |
}, | |
{ | |
"id": 3, | |
"first_name": "Nicole", | |
"last_name": "young", | |
"email": "Nicole@everythingautomation.com" | |
} | |
] | |
} |
From the folder path, open a command widow and type the command
json-server --watch db.json
6. Open POSTMAN, Create GET request with API 'http://localhost:3000/employees'
Hit Send button
You should be able to see the response
Now, you have successfully faked REST APIT with json server and you can play around with your json server with CRUD operations.
------------------------------------------------------------------------------
No comments:
Post a Comment