If you’ve ever noticed a question mark and extra text after a web address, you’ve already encountered query parameters — even if the term sounds unfamiliar. These little additions to URLs let web servers know exactly what data you need, whether you’re sorting a list, filtering search results, or pulling specific records from an API. Understanding how they work gives you a clearer picture of how the web actually communicates behind the scenes.

Location in URL: After question mark (?) · Format: key=value pairs separated by & · Common use: Pass data in GET requests · Example URL part: ?id=123&name=example · Distinguished from: Path parameters

Quick snapshot

1Confirmed facts
  • Query parameters follow ? in URLs (Treblle)
  • Used for optional data like filtering and sorting (Dev.to)
2What’s unclear
  • Precise performance benchmarks comparing path vs query parameter overhead
3Timeline signal
  • RFC 3986 §3.4 formally defined the query component in 2005 (Treblle)
4What’s next
  • Developers increasingly rely on query parameters for flexible API filtering without endpoint proliferation
Field Value
Definition Key-value pairs in URL query string
Syntax ?key1=value1&key2=value2
Max length Typically 2048 characters
HTTP methods Primarily GET

What is a parameter in a query?

A query parameter is a piece of data appended to a URL after a question mark (?), designed to pass additional information to a web server or API endpoint. Per RFC 3986 §3.4, the query component sits at the end of a URI and communicates with the server about what specific data or behavior you need (Treblle).

Query string basics

The question mark acts as a separator between the base URL path and the query string. Each parameter follows a key=value pattern, and multiple parameters chain together using the ampersand (&) symbol. For example, https://api.example.com/products?category=electronics&sort=price asks for electronics sorted by price in one request.

The upshot

Query parameters let clients communicate preferences without changing the underlying endpoint — one URL can return many different results depending on what you append.

Role in URLs

Query parameters do not identify a resource; they refine or filter it. When you search on Google, the query string carries your search terms. When you paginate through results, the offset or page number travels in the query string. The server reads these values, adjusts its response accordingly, and returns data that matches your request.

The implication: query parameters are inherently optional. Removing all of them still leaves a valid, meaningful URL pointing to a resource — even if it returns a default or unfiltered dataset.

What is an example of a query parameter?

Concrete examples make this concept click faster than any abstract explanation. Below are patterns you’ll encounter in real applications.

Simple examples

  • ?id=123 — fetches the record with ID 123
  • ?q=javascript — searches for content matching “javascript”
  • ?status=active — filters records by an “active” status

Complex URL examples

Real-world APIs combine multiple parameters. GitHub’s API demonstrates this clearly: https://api.github.com/user/repos?sort=created&direction=desc retrieves your repositories sorted by creation date in descending order (QAScript). This single URL expresses two separate preferences — sort field and sort direction — through two distinct key-value pairs.

The pattern across these examples: keys describe the attribute you care about, and values tell the server what specific state or behavior you want for that attribute.

Why this matters

Developers can chain filtering, sorting, and pagination into a single request instead of creating separate endpoints for every combination — a cleaner design that scales without endpoint proliferation.

What are query parameters in URL?

A URL with query parameters follows a specific grammar. The structure is hierarchical: base URL, then optional path segments, then the question mark delimiter, then key-value pairs joined by ampersands.

Structure of query strings

Breaking down https://shop.example.com/catalog/shoes?brand=nike&color=black&size=42:

  • https://shop.example.com — the scheme and host
  • /catalog/shoes — the path identifying the resource
  • ? — delimiter marking the start of query string
  • brand=nike&color=black&size=42 — three parameters refining the request

Encoding rules

Special characters cannot travel safely in URLs as-is. Spaces, ampersands within values, and non-ASCII characters must be percent-encoded. A space becomes %20, and an ampersand inside a value becomes %26. This encoding, also defined in RFC 3986, ensures the URL parser correctly identifies where one parameter ends and another begins (Treblle).

Modern browsers and JavaScript handle this automatically via the URLSearchParams API, which encodes values when you build query strings and decodes them when reading (Treblle).

What is query parameter in REST API?

In REST API design, query parameters serve as the mechanism for optional, client-controlled filtering and sorting. They sit at the end of an endpoint URL and influence how the server assembles its response — without changing which resource is being accessed.

REST API specifics

OpenAPI, the standard for describing REST APIs, models query parameters as in: query to distinguish them from path parameters (in: path), header parameters, and request bodies (Treblle). This distinction matters in documentation: when you read an OpenAPI spec, you immediately know whether a parameter travels in the URL path or after the question mark.

The trade-off

CDNs and browsers cache path-based URLs more reliably than those heavy with query strings — an architectural consideration when performance optimization is a priority (Latenode).

GET vs POST

Query parameters belong primarily to GET requests — they travel in the URL itself, which gets logged in browser history, server access logs, and browser bookmarks. POST requests typically send data in the request body instead, not the URL. Using query parameters with POST is possible but unconventional; it signals a design smell unless the API explicitly documents this choice.

For developers: Express.js exposes path parameters through req.params and query parameters through req.query — two distinct objects serving different purposes (Treblle).

What are the differences between query parameters and path parameters?

This distinction sits at the heart of RESTful API design, and confusing the two leads to awkward, harder-to-maintain interfaces.

Key differences

Path parameters live inside the URL path, identifying specific resources or hierarchies. They use placeholders like {id} or {username} to mark where variable values fit (Apipheny API guide). Query parameters sit after the ?, adding optional refinements.

A practical rule from the developer community: if removing the parameter makes the endpoint meaningless, use a path parameter. Otherwise, use a query parameter (Latenode).

Use cases

GitHub’s API illustrates both in action: /users/{username}/repos uses a path parameter because the username identifies which user’s repos to fetch — the endpoint has no meaning without it. Meanwhile, /user/repos?sort=created&direction=desc uses query parameters because sorting direction is optional; you still get repos either way (QAScript).

The catch

Path parameters imply resource hierarchy and ownership — /api/users/123/orders communicates that orders belong to users. Query parameters convey operations like filtering or pagination, not structural relationships.

Three criteria decide which parameter type fits: whether the value is required, whether it defines the resource identity, and whether it implies ownership or hierarchy.

Comparison: Query parameters vs path parameters

Three dimensions separate these two approaches across typical API design scenarios.

Dimension Path parameters Query parameters
Purpose Identify specific resources; define hierarchy Filter, sort, paginate, and refine responses
Required vs optional Required — endpoint meaningless without them Optional — endpoint works with or without them
Location in URL Within the path before ? After the ? separator
Caching behavior CDNs and browsers cache reliably Less cache-friendly due to higher URL variability
Syntax marker Curly braces {id} in specs Equals sign key=value with & joining

The implication: choosing between them shapes both developer experience and system performance — path parameters create cleaner, more cacheable URLs for core resources, while query parameters enable flexible client-side control without endpoint proliferation.

What experts say

Path parameters = resource identification and hierarchy. Query parameters = optional stuff like filtering, sorting, pagination, searching.

— Community Member, Latenode Forum

API parameters are the contract surface of every call: query refines a resource, path identifies it.

— API Expert, Treblle

My quick test: if you remove the parameter and the endpoint becomes meaningless, put it in the path.

— Developer, Latenode Forum

Bottom line: Query parameters handle the optional layer of API requests — filtering, sorting, and pagination that clients control without cluttering your endpoint catalog. Developers building APIs should route essential identifiers through path parameters and let query parameters carry the preferences, ensuring clean URL structures that scale alongside growing feature sets.

Related reading: Is Ketamine an Opioid – Facts, Differences and Uses · How to Backup Your Computer: Windows & Mac 3-2-1 Guide

Additional sources

youtube.com

Query parameters allow flexible filtering in REST APIs, such as the AWS API Gateway REST API, distinguishing them from fixed path parameters in URL design.

Frequently asked questions

What are query strings?

A query string is the portion of a URL that begins with a question mark (?) and contains one or more key-value pairs that pass information to the server. For example, in ?q=web+development, “q” is the key and “web+development” is the value.

How do you encode query parameters?

Special characters must be percent-encoded using %XX syntax. Spaces become %20, ampersands within values become %26, and non-ASCII characters use multi-byte encoding. JavaScript’s URLSearchParams API handles this automatically when building or parsing query strings.

Can query parameters be used in POST requests?

Technically yes, but it is uncommon. POST requests typically send data in the request body rather than the URL. When query parameters appear in POST URLs, they usually indicate optional server-side behavior — but this pattern should be documented explicitly to avoid confusion.

What is the limit on query parameter length?

Most browsers and servers impose a practical limit around 2,048 characters for the entire URL, including the query string. Extremely long query strings risk being truncated in logs or rejected by stricter server configurations.

How to parse query parameters in JavaScript?

The URLSearchParams interface provides the cleanest approach: new URLSearchParams(window.location.search) creates an object you can iterate, read with .get('key'), and modify with .set('key', 'value'). It handles decoding automatically.

Are query parameters case-sensitive?

Yes. ?status=Active and ?status=active are two different queries that may return different results. API behavior depends on how the server parses and matches parameter values — and most servers treat them as case-sensitive strings.

What happens if query parameters have special characters?

Special characters — including &, =, ?, #, and spaces — break URL parsing unless they are percent-encoded. An unencoded ampersand inside a value, for instance, splits it into two separate parameters, causing unexpected behavior.