Ryan
Ryan

Reputation: 25

restify.js route endpoint conflict with parameter

My code is like below:

  1. server.get('/currency/:code', currency.find);
  2. server.get('/currency/rates', currency.rate_getall);

Whenever I try to reach [/rates] endpoint, the server will assume I am passing parameter to '/currency/:code' route. How can I fix this? Thank you.

Ryan

Upvotes: 2

Views: 207

Answers (1)

HeadCode
HeadCode

Reputation: 2828

If you can I would consider changing up your rest interface just a little.

server.get('/currency/:code', currency.find);
server.get('/currency/rates/:type', currency.rate);

That way it solves your initial problem and allows for flexibility in the future if you just want to return a rate for a particular currency.

Inside your currency.rate function you could check for either an id or the literal 'all' and return what is appropriate.

Upvotes: 1

Related Questions