I recently faced a situation where I had to run bulk/batch requests in postman. There are other ways to seed data like a custom script, but let's just focus on how to do it with postman.
Making Batch Requests in Postman
We will need some setup to demonstrate so let's create one.
1. Setup
I created a simple express server with 2 endpoints for creating and returning data. We will store the data in a variable and run the server at port 3000.
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
const port = 3000;
// parse request data
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
let data = [];
app.get("/", (req, res) => res.json(data).status(200));
app.post("/", (req, res) => {
data = [...data, req.body];
res.json(req.body).status(201);
});
app.listen(port, () => console.log(`App listening on port ${port}`));
Now, let's move to postman and create a collection (I am calling it Data Endpoints)
Now let's create 2 requests in the collection (for the 2 endpoints from express server).
- Get Data
- Insert Data
We will be inserting this data. Let's save it in a file (seedData.json).
[
{
"id": 1,
"first_name": "Gary",
"last_name": "Ortiz"
},
{
"id": 2,
"first_name": "Albert",
"last_name": "Williamson"
},
{
"id": 3,
"first_name": "Mildred",
"last_name": "Fuller"
},
{
"id": 4,
"first_name": "Russell",
"last_name": "Robinson"
},
{
"id": 5,
"first_name": "Laura",
"last_name": "Harper"
},
{
"id": 6,
"first_name": "Larry",
"last_name": "Sanders"
},
{
"id": 7,
"first_name": "Michael",
"last_name": "Rice"
},
{
"id": 8,
"first_name": "Sara",
"last_name": "Harris"
},
{
"id": 9,
"first_name": "Phyllis",
"last_name": "Webb"
},
{
"id": 10,
"first_name": "Roger",
"last_name": "Alvarez"
}
]
Now, our setup is complete. Next we will run the actual batch requests.
2. Running Batch Requests
We will be inserting data, so we will need to modify our 'Insert Data' request to allow dynamic data. Something like this
Then, we will need to run the collection.
And select our seedData.json file along with the 'Insert Data' request (then click the 'Run Data Endpoints' button).
It will run the batch requests and give us the results, something like this.
We can use the Get Data request to re-validate data insertion.
.
And that's it. Hope this helps you in your Projects. Thanks 😉
Top comments (1)
its great that you have taking time to sharing such typo of information m with us . I want my love back
Some comments have been hidden by the post's author - find out more