DEV Community

Discussion on: NestJS: stop handling errors like this!

Collapse
 
bishoymelek profile image
bishoymelek

I am sorry but what's the plus you are adding while passing id as a param?

Collapse
 
antoncodes profile image
Anton Bahurinsky

You mean passing the product ID as a URL parameter? Well, the ID could indeed have been passed differently, e.g. as a query parameter or even within a body (not recommended though, especially for GET requests). That's up to developer's choice.
However, by passing the product ID as a URL parameter, we get somewhat neater final URLS, for example:
GET https://mywebapp.com/product/12345
(as opposed to:
GET https://mywebapp.com/product?id=12345)

Collapse
 
techemmy profile image
Emmanuel Temitope

It's for type-casting. @Param('id') id will return a string. Adding a plus converts the string to a number.