Sobes.tech
Intern

What are query parameters?

sobes.tech AI

Answer from AI

Query parameters are key-value pairs added to the URL after the ? symbol. They are used to send additional information to the server during HTTP requests (most commonly GET).

Example URL with query parameters: https://example.com/api/items?category=electronics&sort=price_asc

Here:

  • category=electronics — the first parameter, key category, value electronics.
  • sort=price_asc — the second parameter, key sort, value price_asc.
  • Parameters are separated by an ampersand (&).

Purpose of query parameters:

  • Filtering data: Selecting data based on certain criteria.
  • Sorting data: Determining the order of the retrieved data.
  • Pagination: Specifying page number and number of items per page.
  • Transmitting identifiers: Identifying a resource or user.
  • Additional instructions for the server: For example, which fields to return in the response.

On the server side, the application parses these parameters and uses them to generate a response.

In test automation, query parameters are often used for:

  • Generating test data with different conditions.
  • Checking API logic with various input data.
  • Testing filtering, sorting, and pagination on the backend.

Example of using query parameters in Python with the requests library:

# Sending a GET request with parameters
import requests

url = "https://httpbin.org/get"
params = {
    "param1": "value1",
    "param2": "value2"
}

response = requests.get(url, params=params)

# Checking the status code
print(f"Status code: {response.status_code}")

# Outputting the received parameters
print(f"Received params: {response.json().get('args')}")