restify optional route parameters

Viewed 12916

Hi I have an routing issue with restify.io

It seems like restify does not support the "?" for optional parameters as express.js does.

server.get('/users',function(req,res,next){});
server.get('/users/:id',function(req,res,next{});

// I even tried server.get('/users/',function(req,res,next){});

So everything works as expected when I run

1

http://localhost/users

which shows all my users

2

http://localhost/users/1 

which shows the user with id 1

http://localhost/users/ //(note trailing slash)

fails with resource not found because this one is interpreted as empty parameter instead of route #1

I don't want the check for empty parameters on each and redirect or pass on to next ...

This seems like a common thing which should hit others too... so what is your take on that to not get an 404 for trainling slashes in the url

2 Answers
Related