You must have seen filter results feature in e-commerce platform like amazon. We can filter through multiple different parameters like price, ratings etc to get just the products we are interested in.
Query parameters are very similar to the filter results feature that we see so regularly. Extending the same analogy, let us say there is an API which gives search results for a product like camera. Now, if have to filter the search results, it is generally considered good design to use query parameters.
Let us now try to understand how query parameters are passed to an API by taking the example of searching for a camera at fictional online store amazin.
If we are searching for just camera, the API call would look something like this
The search result will contain all cameras in the store.
Now, we are interested in cameras which are of a particular brand called nakon. The Api call would look something like this
Notice that we start query parameters with
? mark followed by query parameter name and query value.
We want to further refine our search and see only cameras with review rating greater than 3. The Api call to achieve this would look something like this.
Notice that the second and subsequent query parameters are using
? is used only at the beginning of the query parameters.
Read here, to understand how to pass query parameter in python.