A search parameter helps you find specific information from a large set of data by telling the system what to look for.
Search parameter in Rest API
GET /resource?searchKey=searchValue
The search parameter is added after the question mark (?) in the URL.
Multiple parameters can be added using the ampersand (&) symbol.
GET /users?name=alice
GET /products?category=books&price=20GET /events?date=2024-06-01
This program sends a request to a web API to find users named 'bob'. It then prints how many users were found and their details.
import requests # URL with search parameter to find users named 'bob' url = 'https://api.example.com/users?name=bob' response = requests.get(url) if response.status_code == 200: users = response.json() print(f"Found {len(users)} users named 'bob':") for user in users: print(f"- {user['name']} (ID: {user['id']})") else: print('Failed to get users')
Search parameters are case sensitive depending on the API.
Always encode special characters in search values to avoid errors.
Check API documentation for supported search keys and formats.
Search parameters help filter data by specifying what you want.
They are added to the URL after a question mark (?).
Multiple parameters can be combined using &.
Practice
What is the main purpose of a search parameter in a REST API URL?
Solution
Step 1: Understand what search parameters do
Search parameters are added to the URL to specify what data you want from the API.Step 2: Identify the purpose of filtering
Filtering means selecting only the data that matches your criteria, which is what search parameters do.Final Answer:
To filter the data returned by the API -> Option BQuick Check:
Search parameter = filter data [OK]
- Thinking search parameters change server address
- Confusing search parameters with security tokens
- Assuming search parameters format response
Which of the following is the correct way to add a search parameter named name with value alice to a REST API URL?
https://api.example.com/users
Solution
Step 1: Recall the syntax for search parameters
Search parameters start with a question mark (?) after the base URL.Step 2: Check the correct separator and format
The parameter is added as?name=alice. Using & or # or slashes is incorrect here.Final Answer:
https://api.example.com/users?name=alice -> Option CQuick Check:
Use ? before first parameter [OK]
- Using & instead of ? for first parameter
- Using # which is for anchors, not parameters
- Adding parameters as path segments
What will be the full URL to search for users with age 30 and city as NY?
Base URL: https://api.example.com/users
Solution
Step 1: Add first parameter with ?
The first search parameter starts with a question mark:?age=30.Step 2: Add second parameter with &
Additional parameters use & to separate:&city=NY.Final Answer:
https://api.example.com/users?age=30&city=NY -> Option AQuick Check:
First ? then & for multiple parameters [OK]
- Using ? for every parameter
- Using & before first parameter
- Using # which is for anchors
Identify the error in this URL with search parameters:
https://api.example.com/products?category=books&price=20?sort=asc
Solution
Step 1: Check parameter separators
Only the first parameter uses ?, others must use &.Step 2: Identify the error in the URL
The URL incorrectly uses a second ? beforesort=ascinstead of &.Final Answer:
Using two question marks (?) for parameters -> Option AQuick Check:
Only one ? allowed, others use & [OK]
- Using multiple ? instead of &
- Confusing = with : in parameters
- Thinking parameters belong in URL path
You want to search a REST API for books with author as John and year greater than 2010. Which URL correctly uses search parameters to do this?
Solution
Step 1: Understand how to express 'greater than' in search parameters
REST APIs often use suffixes like _gt for 'greater than' in parameters.Step 2: Check each option for correct syntax
https://api.example.com/books?author=John&year_gt=2010 usesyear_gt=2010, which is a common and correct way to express this filter.Final Answer:
https://api.example.com/books?author=John&year_gt=2010 -> Option DQuick Check:
Use _gt suffix for greater than filters [OK]
- Using > directly in URL parameter
- Placing operators after values
- Confusing parameter syntax for filters
Ready to prove it?
Pass the test and this pattern moves unknown
