B
B
Boniface2014-05-10 13:57:18
JavaScript
Boniface, 2014-05-10 13:57:18

Express.js routing pagination question

Hello!
The question is how to set up routes in express.js to accept such requests localhost/somethings?take=10&skip=15
You can of course just receive a request for /somethings and there already determine whether the parameters were passed or not. But I would like to make it more beautiful. On the Internet, I found only options with a slash, for example, /somethings/take/10/skip/15 - but this is not beautiful in my opinion.
It seems all the same to determine such a route, is it possible without regular expressions?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene Obrezkov, 2014-05-10
@ghaiklor

Define the somethings route, and in the action itself we are already looking:

var take = req.param('take') || 10,
    skip = req.param('skip') || 0;

B
Boniface, 2014-05-10
@Boniface

Yes, that's what I'm talking about

You can, of course, just receive a request for /somethings and there already determine whether the parameters were passed or not.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question