Query parameters are values added to the end of an API URL to send additional information to the server. In Postman, query parameters are commonly used for searching, filtering, sorting, and selecting specific data.
A query parameter is a value added to the URL after a question mark ?.
Example:
http://localhost/api/students.php?course=ADCA
Here, course=ADCA is a query parameter.
A query parameter generally follows this structure:
?key=value
Example:
?course=ADCA
The key is course and the value is ADCA.
The first query parameter is separated from the API URL using a question mark.
http://localhost/api/students.php?course=ADCA
The ? indicates the beginning of the query string.
A query parameter contains a key and a value separated by an equals sign.
course=ADCA
Postman provides a dedicated Params section for adding query parameters.
Instead of manually typing the query string, you can add the key and value in the Params table.
After entering the API URL, click the Params tab in Postman.
You will see fields for:
Enter the query parameter in these fields.
Suppose we want to retrieve students from the ADCA course.
In the Params section enter:
Key: course
Value: ADCA
Postman will add the parameter to the URL.
After adding the parameter, the URL becomes:
http://localhost/api/students.php?course=ADCA
The server can read the course value and use it to filter the results.
An API can accept multiple query parameters.
Multiple parameters are separated using an ampersand &.
?course=ADCA&city=Patna
Here there are two query parameters.
Suppose we want ADCA students from Patna.
http://localhost/api/students.php?course=ADCA&city=Patna
The API can use both values to filter the data.
A query parameter can be used to search for a particular value.
Example:
http://localhost/api/students.php?search=Rahul
The API can search for students whose information matches the search value.
A course parameter can be used to filter students.
http://localhost/api/students.php?course=Python
The API can return only students belonging to the Python course.
Query parameters can also be used to filter records by status.
Example:
http://localhost/api/students.php?status=active
The API can return only active students.
A query parameter can also be used to identify a specific resource.
http://localhost/api/student.php?id=10
The API can use the ID to retrieve the student with ID 10.
Query parameter values can also represent numbers.
http://localhost/api/products.php?price=500
The API can interpret the value as a number when appropriate.
Query parameters are commonly used with GET requests.
GET
http://localhost/api/students.php?course=ADCA
The API can read the parameter and return matching data.
POST requests can also contain query parameters when an API is designed to accept them.
POST
http://localhost/api/students.php?source=mobile
The request body can still contain JSON data.
A PUT request can also contain query parameters when required by the API.
PUT
http://localhost/api/students.php?id=10
The API can use the ID to identify the resource.
DELETE requests can also use query parameters to identify a resource.
DELETE
http://localhost/api/students.php?id=10
The API can use the ID to identify the record that should be removed.
Spaces and special characters in query values need proper URL encoding.
For example, a value such as:
Rahul Kumar
may be encoded in a URL as:
Rahul%20Kumar
Postman can handle URL encoding when parameters are entered through the Params section.
Sometimes a query parameter may have an empty value.
?search=
The API should decide how to handle an empty parameter.
In Postman, review the parameter value before sending the request.
Postman's Params section allows parameters to be enabled or disabled.
This is useful when testing different versions of a request without removing the parameter completely.
For example, you can temporarily disable:
course=ADCA
Query parameters are commonly used for pagination.
For example:
http://localhost/api/students.php?page=2&limit=10
Here:
Query parameters can also be used to request sorted data.
Example:
http://localhost/api/students.php?sort=name
The API can interpret the sort parameter and return the data accordingly.
Filtering is one of the most common uses of query parameters.
Example:
http://localhost/api/students.php?course=ADCA&status=active
The API can use both parameters to filter the results.
If a query parameter does not work, check:
React Native applications can send query parameters when requesting data from REST APIs.
GET
http://localhost/api/students.php?course=ADCA
The mobile application can use the returned JSON data to display filtered results.
Method:
GET
URL:
http://localhost/api/students.php
Params:
| Key | Value |
|---|---|
| course | ADCA |
| status | active |
Generated URL:
http://localhost/api/students.php?course=ADCA&status=active
Click Send to test the request.
Query parameters allow additional information to be sent through an API URL. In Postman, they can be added easily through the Params section. They are commonly used for searching, filtering, sorting, pagination, and selecting specific resources.
API URL
↓
?
↓
key=value
↓
&
↓
key=value
↓
REST API
Question: Which symbol is used to start the query string in a URL?