Friday 17 March 2017

Nodejs request params and query string

TL;DR; I would like the GET url to be without parameter (/api/:parameter) and have only the query string (/api/search=value&offset=number)

Hello everyone,

I was recently using express to build some routes and I came across the use of the Bing Image Search API.

In my backend scripts, I call the API and request images based on a query string that is sent by the user to my server. I pre-process the query string parameters and then I make an ajax request to the Bing API for images based on the query string passed by the user.


Route /api/

app.get("/api/:parameter", function(req, res){
    var querystring = req.query.search;
    var offset = req.query.offset || 10;


Right now if I go to www.mywebsite.com/api/anything?search=this&offset=100 the req.query.* are set to search and offset, so the url works, but I would like a behaviour like www.mywebsite.com/api/search=this&offset=100 without the need to actually put any parameters to the endpoint.

What would the GET url be for that to work?



via mnemosdev

No comments:

Post a Comment