Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array as parameter in GET request in Postman

I have to send array of ids in GET request as paramenter.How can I test it in Postman(google chrome extension for API testing)?

The scenario is I have url, www.something.com/activity/poi_ids

poi_ids should conatain arrays of ids like [316,318]

At api side using express,

app.get('/activity/:poi_ids',function(req,res){
    var poi_ids = req.params.poi_ids;
    .......
    .......
});

I have looked into it but it is only for post request

like image 212
xruptronics Avatar asked Aug 11 '16 09:08

xruptronics


People also ask

How do you send an array in GET request postman?

If you are using the postman packaged app, you can send an array by selecting raw / json (instead of form-data ). Also, make sure to set Content-Type as application/json in Headers tab. Here is example for raw data {"user_ids": ["123" "233"]} , don't forget the quotes!

How do you pass parameters in Postman GET request?

To send a path parameter, enter the parameter name into the URL field, after a colon, for example :id . When you enter a path parameter, Postman will populate it in the Params tab, where you can also edit it.

Can Request body be an array?

An API may accept a JSON Array payload as a request body. Imagine, we want to add employee details of more than one employee in the below example. In this case, we can pass multiple JSON objects within a JSON array.


2 Answers

you can send them via query params .. in your http query params assign all values to same variables like

GET activity?pid=12&pid=23&pid=34

and then inside your express get it like

var ids=req.query.pid; //[12,23,34]
like image 113
Waqas Noor Avatar answered Nov 14 '22 21:11

Waqas Noor


It is unstructured text. If you want to "send an array" then you'll need to design some way to encode it and then write JavaScript to decode it.

For example:

GET /activity/316-318

and

var poi_ids = req.params.poi_ids.split("-");
like image 43
Quentin Avatar answered Nov 14 '22 23:11

Quentin