Depends on what you are using to build your API. In the case of express (and loopback), a route of the type:
app.get('/', (req, res, next) => {
});
You can capture the query string parameters using req.query
. For example:
app.get('/', (req, res, next) => {
console.log(req.query);
});
If you call a URL of the type
http://localhost:3000/?a=1&a=2&a=3
The console logs:
{ a: [ '1', '2', '3' ] }
If you are using another framework, the important thing is that you have access to the variable that contains the complete URL of the request, and use the module url
that is built into node. Let's say:
var address = 'http://localhost:3000/?a=1&a=2&a=3';
var url = require('url');
var url_parts = url.parse(address, true);
console.log(url_parts.query);
And that prints the same as the example above