Onjsdev

Share


Query parameters are key-value pairs that are appended to a URL after a question mark (?), and separated by ampersands (&)

What are Query Parameters?


By onjsdev

Feb 10th, 2024

Query parameters are key-value pairs that are appended to a URL after a question mark (?), and separated by ampersands (&). They allow us to send additional information to a web server without altering the actual URL path

Here's a basic example of a URL with query parameters:

https://www.example.com/page?name=John&age=25

In this example:

  • https://www.example.com/page is the base URL.
  • ? indicates the start of the query parameters.
  • name=John and age=25 are two query parameters, where name and age are the keys, and John and 25 are their respective values.

Use Cases

Query parameters can be used for various purposes, including:

Filtering and sorting content

They are used to filter search results, products, or other content by specifying criteria

https://api.example.com/products?price=10-50&sort=rating

Pagination

To [navigate through multiple pages (https://onjsdev.com/article/guide-to-nodejs-postgresql-pagination) of content query parameters are mostly used to specify the desired page number.

https://www.example.com/articles?page=2

Passing data to forms

Data in query parameters can be used to pre-fill form fields

https://www.example.com/page?name=John&gender=Male

Tracking website traffic

Query parameters is used to track website traffic by including information like the referring website or campaign ID.

https://www.example.com/product/123?utm_source=email&utm_campaign=promo

Conclusion

In conclusion, query parameters offer a way to easily pass additional information to server without modifying the actual URL path. I hope this article provides a good overview of query parameters.

Thank you for reading