Saturday, April 17, 2021

How to Fake or Mock an API with JSON Server : Simple and Easy steps




******************************************************************************
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

3. Create the db.json file in folder
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.

4. Once the db.json file is created, navigate to the folder where the file is saved.
From the folder path, open a command widow and type the command

json-server --watch db.json

5. Now check if you can able to access json server and it is up and running by hitting 'http://localhost:3000'
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

How to install Java on EC2

***************************************** How to install Java on EC2 ***************************************** To be continued, In this post...

All Time Popular Post