Running Batch Requests In Postman
Tags: api, tutorial, node
Published: 2022-02-13 12:59:30

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.
```js
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**)
![Postman Collection Creation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7rismf5y9tl62p9pl3w2.png)

![Postman Collection Created](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zutk7yvrvm0cuah56kub.PNG)

Now let's create 2 requests in the collection (for the 2 endpoints from express server).

-  Get Data
-  Insert Data

![Postman Collection with Endpoints](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l97n3l2posb85f95x33b.png)

We will be inserting this data. Let's save it in a file (**seedData.json**).
```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
![Postman Post Request With Dynamic Json Data](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mqmtzxi832jvgd9urwqg.png)
 
 

Then, we will need to run the collection.
![Postman Run Collection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ezru67o7q7jqfprckmra.png)

And select our **seedData.json** file along with the '**Insert Data**' request (then click the '**Run Data Endpoints**' button).
![Postman Run Collection With Dynamic Data](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/65akq6ettmzsqze8kl6g.png)

It will run the batch requests and give us the results, something like this.
![Postman Run Collection With Dynamic Data Result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqs7zsmtpzxz9kxdllc6.png)

We can use the **Get Data** request to re-validate data insertion.
![Postman Get Data Request](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/euobs2n1ga9whyz326q8.png).

And that's it. Hope this helps you in your Projects. Thanks 😉