An Interest In:
Web News this Week
- March 13, 2024
- March 12, 2024
- March 11, 2024
- March 10, 2024
- March 9, 2024
- March 8, 2024
- March 7, 2024
Fake REST API with JSON and POSTMAN
You need back end data to connect with your front end? I will show you how to create fake JSON data with json-server and Postman.
I assume you have your project open, let's type this command to your terminal npm install -g json-server
After installation is done create a db.json
file with some data.
Example:
{ "groceries": [ { "id": 1, "item": "bread", "amount": "1" }, { "id": 2, "item": "milk", "amount": "3" } ]}
Start JSON Server json-server --watch db.json
It should look like this in the browser.
I assume you have Postman installed, we will make a GET request.
Let's add one item with POST request.
Pros:
The dummy data is in your version control system
The simplest setup you can imagine
It supports the most used http verbs
It saves changes to your JSON source for POST, PUT, PATCH or DELETE requests.
Cons:
The payload requires a strict format (JSON)
If you are more for a video on how to do it, I highly recommend to watch this video
This is helpful to filter your data.
GET ALL GROCERIEShttp://localhost:3000/groceriesGET SINGLE GROCERYhttp://localhost:3000/grocery/1PAGINATION & LIMIThttp://localhost:3000/groceries?_page=1&_limit=2SORTINGhttp://localhost:3000/groceries?_sort=name&_order=ascFULL TEXT SEARCHhttp://localhost:3000/groceries?q=milk
Dummy data generators
https://github.com/Marak/faker.js
https://github.com/boo1ean/casual
https://github.com/chancejs/chancejs
I hope you will find this article helpful for your future projects.
Original Link: https://dev.to/tadea/fake-rest-api-with-json-and-postman-5gi8
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To