Lesson 41 of 158 – Postman Query Parameters
41%

Postman Query Parameters

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.

Note: Query parameters are especially useful when a React Native application needs to request specific data from a REST API.

1. What is a Query Parameter?

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.

2. Query Parameter Structure

A query parameter generally follows this structure:

?key=value

Example:

?course=ADCA

The key is course and the value is ADCA.

3. Question Mark in a URL

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.

4. Key and Value

A query parameter contains a key and a value separated by an equals sign.

course=ADCA
  • Key: course
  • Value: ADCA

5. Query Parameters in Postman

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.

6. Open the Params Section

After entering the API URL, click the Params tab in Postman.

You will see fields for:

  • Key
  • Value

Enter the query parameter in these fields.

7. Add the First Query Parameter

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.

8. URL After Adding Parameter

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.

9. Multiple Query Parameters

An API can accept multiple query parameters.

Multiple parameters are separated using an ampersand &.

?course=ADCA&city=Patna

Here there are two query parameters.

10. Example of Multiple 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.

11. Query Parameter for Search

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.

12. Query Parameter for Course Filter

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.

13. Query Parameter for Status

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.

14. Query Parameter for ID

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.

15. Numeric Query Parameters

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.

16. Query Parameters and GET

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.

17. Query Parameters and POST

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.

18. Query Parameters and PUT

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.

19. Query Parameters and DELETE

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.

20. Query Parameters and Spaces

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.

21. Query Parameters and Empty Values

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.

22. Enable and Disable Parameters

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

23. Query Parameters for Pagination

Query parameters are commonly used for pagination.

For example:

http://localhost/api/students.php?page=2&limit=10

Here:

  • page=2 requests page 2.
  • limit=10 requests up to 10 records.

24. Query Parameters for Sorting

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.

25. Query Parameters for Filtering

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.

26. Common Query Parameter Mistakes

  • Incorrect parameter name
  • Incorrect parameter value
  • Missing question mark
  • Using the wrong separator
  • Missing ampersand between parameters
  • Incorrect URL encoding
  • Sending parameters that the API does not support

27. Debugging Query Parameters

If a query parameter does not work, check:

  1. Open the Params section.
  2. Check the parameter key.
  3. Check the parameter value.
  4. Check whether the parameter is enabled.
  5. Check the generated URL.
  6. Check the API documentation.
  7. Check the server-side API code.
  8. Send the request again.

28. Query Parameters and React Native

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.

29. Complete Postman Query Parameter Example

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.

30. Postman Query Parameters Summary

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

📌 Key Points

  • Query parameters are added to the API URL.
  • The first query parameter starts after the ? symbol.
  • Key and value are separated using =.
  • Multiple parameters are separated using &.
  • Postman provides a Params section for query parameters.
  • Query parameters are commonly used with GET requests.
  • They can be used for searching and filtering.
  • They can be used for sorting and pagination.
  • They can identify a specific resource.
  • React Native applications can send query parameters to REST APIs.

🧠 Quick Quiz

Question: Which symbol is used to start the query string in a URL?