๐Ÿ“ API

URL Structure and Query Parameters

P
Author
PyLand Team
๐Ÿ“…
Published
08.05.2026
โฑ๏ธ
Reading time
1 min
๐Ÿ‘๏ธ
Views
356
๐ŸŒฑ
Level
Beginner

Every HTTP request targets a specific address. Understanding URL structure means you can read requests like plain text instead of guessing what’s going on.

Anatomy of a URL

https://api.chucknorris.io/jokes/random?category=dev&limit=5
โ”‚      โ”‚                   โ”‚            โ”‚
โ”‚      โ”‚                   โ”‚            โ””โ”€โ”€ query parameters
โ”‚      โ”‚                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ path
โ”‚      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ host
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ scheme (protocol)
  • Scheme (https://) โ€” the data transfer protocol. Always use https, not http
  • Host (api.chucknorris.io) โ€” the server address
  • Path (/jokes/random) โ€” the specific resource on the server
  • Query parameters (?category=dev) โ€” additional data for filtering or configuration

Query Parameters: Syntax

Query parameters start with ? and are written as key=value pairs:

?category=dev

Multiple parameters are separated by &:

?category=dev&limit=5&lang=ru

The Problem with Building URLs Manually

Assembling URLs by hand with f-strings is error-prone:

# Bad โ€” manual construction
city = "New York"
url = f"https://api.example.com/weather?city={city}"
# Result: ?city=New York โ€” the space will break the request!

Spaces and special characters (&, /, #, ?) in parameter values need to be URL-encoded:
- space โ†’ %20
- & โ†’ %26
- / โ†’ %2F

Doing this by hand is a common source of bugs.

The Right Way โ€” params= in requests

The requests library handles encoding automatically:

import requests

response = requests.get(
    "https://api.chucknorris.io/jokes/random",
    params={"category": "dev"}
)
# Resulting URL: .../jokes/random?category=dev

Spaces are handled correctly too:

response = requests.get(
    "https://api.example.com/search",
    params={"q": "New York", "lang": "ru"}
)
# Resulting URL: .../search?q=New+York&lang=ru

Inspecting the Final URL

It’s sometimes useful to check what URL requests actually built:

response = requests.get(url, params=params)
print(response.url)  # prints the full URL with parameters

Path Parameters vs Query Parameters

There are two ways to pass data in a URL:

Path parameter โ€” part of the path itself, required:

/repos/torvalds/linux/issues
       โ”‚        โ”‚
       owner    repo

Query parameter โ€” after ?, usually optional:

/repos/torvalds/linux/issues?state=open&per_page=10

The API documentation always specifies which type is used for each parameter.

Summary

Element Example Purpose
Scheme https:// Protocol
Host api.github.com Server address
Path /user/repos Resource
Query parameters ?sort=updated Filters and options

Use params= in requests instead of building URLs manually โ€” it’s more reliable and more readable.

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

REST API Design Principles

Covered topics: Resources and URLs, HTTP methods, Nested resources, Response codes.

๐Ÿ“… 30.06.2026 ๐Ÿ‘๏ธ 273
๐Ÿ“

API Keys: What They Are and How to Use Them

Most public APIs require an API key โ€” a unique string that identifies you as...

๐Ÿ“… 08.05.2026 ๐Ÿ‘๏ธ 374
๐Ÿ“

The requests Library: HTTP Requests from Python

requests is the most downloaded Python library in the world โ€” over 300 million downloads...

๐Ÿ“… 08.05.2026 ๐Ÿ‘๏ธ 342
๐ŸŽ“ Continue learning

Courses that cover this material

Visit the course to apply this material in practice.

API in Practice: Interact with Any Service Open course curriculum