URL Parameters vs Query Strings in Express.js

Today we will discuss about a easy concept of http api . this concept may sound fancy but it is used in almost all websites.
For starters they help to pass variable values to the urls . These variables can be used to process dynamic data on the page .
for eg , there are million of users of facebook. Will engineers write a separate page for each user ?
Not possible right 😂
What are URL parameters?
if parameter is a long word you too then they have a shorter name k.a. params . most of the professionals use this name instead of complete one.
Url : https://hashnode.com/draft/69e243b6fd22b8ad623bb2a4
this is the draft page url for me . do you notice a random string at last.
that is the most probably the unique id that helps the website to load the correct draft .
all draft urls are same till https://hashnode.com/draft/ after this the id of the draft is appended .
what is Query String ?
It is key-value pairs appended to the end of a URL after a question mark (?) to provide additional information to a web server.
http://example.com/?bar1=a&bar2=b
here after ? we can see there are some key value pairs ,and each are separated by & .
These are also used to pass variable values as in parameters.
When to use Query vs Params ?
there is no hard and fast rule . But yes there are some good conventions that needs to be followed .
if you want data about some specific resource like userId , product Id you use params
GET /users/123 // <- 123 is user id GET /posts/456 // <- 456 is product id GET /products/789/reviewsIf the structure of the data is dynamic like users filtering the product list you will use query strings
GET /products?page=2&sort=price // here page and sort is mentioned




