xruptronics xruptronics - 3 months ago 36
Node.js Question

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

Answer

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("-");