Guides › Path vs Query Parameters: How to Ask for What You Want
Path vs Query Parameters: How to Ask for What You Want
When you ask an API for data, you need to tell it which records you want. APIs give you two distinct places in the URL to pass options: path parameters and query parameters.
Think of an office filing cabinet. The drawer label on the outside points directly to one specific folder: that is a path parameter (like /v1/names/3). Once you open that drawer, the colored sticky tabs and filter dividers that let you browse or narrow down pages inside the folder are query parameters (like /v1/names?limit=3&offset=3).
The core difference
- Path parameters point to a specific identity. Use them to pick one exact item, such as
/v1/names/7. If the item does not exist, the API returns 404. - Query parameters follow a question mark
?and are joined with ampersands&. Use them to filter, sort, or page through collections, like/v1/names?limit=3&offset=3.
See them in action three ways
1. In your browser
Visit https://api.computewithpour.com/v1/names/3 to fetch one person. Then compare that with a filtered collection by visiting https://api.computewithpour.com/v1/names?q=g to see only names starting with the letter G.
2. With curl
Pass query strings to curl inside quotation marks so your terminal does not misinterpret the & symbol:
curl "https://api.computewithpour.com/v1/names?limit=3&offset=3"
3. With Python
In Python, you do not need to assemble URL question marks by hand. Pass a dictionary into the params argument of requests.get, and Python handles the formatting automatically:
import requests
base = "https://api.computewithpour.com"
r = requests.get(f"{base}/v1/names", params={"limit": 3, "offset": 3})
data = r.json()
print("Count in this page:", data["count"]) # 3
print("Total in database:", data["total"]) # 12
print("Names:", [item["name"] for item in data["results"]])
Try it in the API Lab
Head to the API Lab and run GET /v1/names/7, then test GET /v1/shortcuts?os=mac. Notice how the query parameter zeroes out the irrelevant Windows column while preserving the matching rows.
What to notice
Look closely at the JSON envelope returned by /v1/names. It includes both count (the number of items in this specific page) and total (the total number of matching items in the system). Using limit and offset together is called pagination, which keeps network responses fast and lightweight.
From messy spreadsheets to clean systems
When teams manage customer lists and inventory in spreadsheets, pagination, filtering, and unique IDs are often handled by slow, fragile macros. Understanding how databases and APIs structure parameters is the first step toward building dependable business tools. When you are ready to modernize your company's workflows, read Off the Spreadsheet, Onto the System in our library.
Challenge
Use query parameters to solve these three tasks: (a) fetch names starting with 'g', (b) fetch names 4, 5, and 6 in a single page, and (c) find out how many total names exist in the dataset. Write a Python script to verify all three.
Show the answer
(a) /v1/names?q=g returns Grace and Guido. (b) /v1/names?limit=3&offset=3 skips 3 and takes 3, giving Guido, Margaret, and Alan. (c) The total key in the returned dictionary tells you exactly 12 names exist, regardless of limit.
import requests
base = "https://api.computewithpour.com"
q_resp = requests.get(f"{base}/v1/names", params={"q": "g"}).json()
print("Starting with 'g':", [n["name"] for n in q_resp["results"]])
page_resp = requests.get(f"{base}/v1/names", params={"limit": 3, "offset": 3}).json()
print("Page (4, 5, 6):", [n["name"] for n in page_resp["results"]])
print("Total records available:", page_resp["total"])