Hello guys,
In this small article, I am going to show you the Difference between req params req body and req query in Nodejs
How req.params works
req.params
get the data from the segment of the url where the route name starts with " : "
. For eg: https://localhost:8081/movie/:movieid
becomes https://localhost:8081/movie/5896544
Now the required code to get the value of req.params.movieid
is 5896544
So,
req.params.movieid = 5896544
How req.body works?
req.body
properties come from a form post or body section where the form data has been parsed into properties.
How req.query works?
req.query comes from query parameters in the URL such as https://localhost:8081/movie?name=boss
where req.query.name === "boss"
.
Hope you are now clear between the key difference between request-params, request-body and request-query.
Leave a Reply