How Express routes similar url links?

Viewed 100

Developing web app with node.js and express.

I have following two urls to distinguish:

  1. /api/v1/source?id=122323
  2. /api/v1/source?timestamp=1555050505&count=10

I come up a naive solution. I leave such similar urls to one route method and use if eles to specify solutions, i.e:

if(id){
//solution with id 
}

if(timestamp&&count){
//solution with timestamp and count but without id 
}

Apparently, this is not clean. Because in the future,I may want to add new field which will make this router huge and ugly.

So How can I overcome this? Or to change url structure.I want to build a Restful api.

2 Answers
Related