leo
leo

Reputation: 3055

Rest API on express. Parameter passing

Folks, I need your expert advice: I have two endpoints on my node server using express:

'/api/status/:id'
'/api/status/all'

Now both have different purpose. One returns one status by Id and other one is all statuses. But express seems to be taking both request as the first one hence it is breaking on cast error. any help please.

Upvotes: 1

Views: 143

Answers (1)

Aren Hovsepyan
Aren Hovsepyan

Reputation: 2047

You can define '/api/status/all' before '/api/status/:id' and if request will match to all it will be handled with that middleware.

Upvotes: 3

Related Questions