On this page
A useful query parameter reference tells client developers not only which names to send, but also how to serialize values, combine parameters, and handle failures. This guide shows how to document API query parameters as a precise contract, with an OpenAPI example and a review checklist.
Key Takeaways
- Document each parameter’s name, location, type, required status, default, allowed values, and repeatability.
- Describe relationships between parameters explicitly; individual schemas may not express cross-parameter rules.
- Show encoded requests and error responses, but enforce the contract with server-side validation.
- Treat defaults, duplicate keys, empty values, and unknown parameters as deliberate API design choices.
Describe the contract for each parameter
For each query parameter, give readers enough information to construct a request without guessing:
- Name and location: Specify the exact, case-sensitive name and that it appears in the query string.
- Type and format: For example, an integer, a string, or an RFC 3339 date-time string. Explain any length or range limits.
- Required status: Say whether omission is allowed, and describe conditional requirements separately.
- Default: State what the server does when an optional parameter is omitted. A schema default alone does not guarantee that a server inserts that value.
- Allowed values: List enum values or constraints, including whether comparisons are case-sensitive.
- Repeatability: Explain whether the key can occur more than once, how repeated values are interpreted, and what happens to duplicate scalar parameters.
- Meaning: Describe the effect of the value, including units, boundaries, and ordering where relevant.
For example, an API might define limit as an optional integer from 1 to 100, defaulting to 20 when omitted. That is more useful than saying only that limit controls pagination: it tells clients which values are valid and what omission means.
Advertisement
Example: optional, required, and dependent parameters
The following fictional GET /events contract illustrates the choices. These are example API rules, not universal HTTP requirements.
| Parameter | Contract |
|---|---|
account_id | Required, non-empty string identifying the account to query. Authorization is still checked separately. |
limit | Optional integer from 1 to 100; defaults to 20 when omitted. |
sort | Optional, case-sensitive string: created or updated; defaults to created. |
tag | Optional repeatable string; one to five non-empty values. An event matches if it has any supplied tag. |
from and to | Optional RFC 3339 date-time strings, but either both must be supplied or neither. from must be earlier than to; the interval includes from and excludes to. |
For this example, the server rejects unknown parameters, empty values, and repeated scalar parameters with HTTP 400. tag is the only repeatable parameter. The server also checks that the caller is authorized to access the requested account.
A request using the optional and required parameters could look like this:
GET /events?account_id=acct_123&limit=10&sort=updated&tag=release&tag=security HTTP/1.1
Host: api.example.com
The following request supplies both dependent parameters. The colons inside the date-time values are percent-encoded:
GET /events?account_id=acct_123&from=2025-01-01T00%3A00%3A00Z&to=2025-02-01T00%3A00%3A00Z HTTP/1.1
Host: api.example.com
Supplying from without to, or setting from equal to or later than to, violates this example contract. Documenting the relationship matters even when both parameters are individually optional.
Express the contract in OpenAPI
This OpenAPI 3.1 example describes the individual parameters and gives the cross-parameter rule in prose. For tag, style: form with explode: true describes repeated keys such as tag=release&tag=security.
openapi: 3.1.0
info:
title: Events API example
version: 1.0.0
paths:
/events:
get:
description: |
Unknown parameters, empty values, and repeated scalar parameters
are rejected. Supply both from and to, or neither. From must be
earlier than to; the interval includes from and excludes to.
parameters:
- name: account_id
in: query
required: true
description: Account identifier; the caller must be authorized to access it.
schema:
type: string
minLength: 1
- name: limit
in: query
required: false
description: Maximum number of events to return.
schema:
type: integer
minimum: 1
maximum: 100
default: 20
- name: sort
in: query
required: false
description: Sort field; values are case-sensitive.
schema:
type: string
enum: [created, updated]
default: created
- name: tag
in: query
required: false
description: Return events matching any supplied tag.
style: form
explode: true
schema:
type: array
minItems: 1
maxItems: 5
items:
type: string
minLength: 1
- name: from
in: query
required: false
description: Inclusive start; requires to.
schema:
type: string
format: date-time
- name: to
in: query
required: false
description: Exclusive end; requires from and must be later than it.
schema:
type: string
format: date-time
responses:
'200':
description: Matching events.
'400':
description: Invalid query parameters.
This is a documentation example, not a complete API definition or server implementation. In particular, individual parameter schemas do not enforce the from/to relationship across separate parameters. Implement and test that rule on the server; check how your chosen validators and client generators interpret formats, defaults, and serialization.
Editorial limitation: OpenAPI documentation could not be consulted in this environment. Verify the example against the official OpenAPI 3.1 specification and your tooling before publication or implementation.
Advertisement
Document encoding and error behavior
State the encoding convention your endpoint accepts. For this example contract, clients should encode query parameter names and values as UTF-8 and percent-encode data that would otherwise be interpreted as a delimiter. For instance, a literal ampersand in a tag value is %26, not &:
GET /events?account_id=acct_123&tag=research%26development HTTP/1.1
Host: api.example.com
Here the tag value is research&development; the encoded ampersand does not start another parameter. Do not encode the structural ?, &, and = characters that separate the query string and its parameters. Prefer a URL-building library over manually concatenating untrusted values.
Also specify how the server handles +. In form-style query decoding, + commonly represents a space; encode a literal plus as %2B and use %20 for a space when constructing examples. Document and test the actual behavior of your server and intermediaries rather than assuming every query parser behaves identically. Reject malformed encodings, and avoid accidental double decoding.
Give clients a predictable error contract. For the fictional endpoint, an unpaired from could produce:
HTTP/1.1 400 Bad Request
Content-Type: application/json
{"error":{"code":"invalid_parameter_combination","message":"from and to must be supplied together"}}
Document the status codes, stable machine-readable error codes, response shape, and whether errors identify the offending parameter. Cover missing required values, invalid types or enum values, out-of-range values, duplicates, and invalid combinations. Separately document authentication and authorization failures as applicable. Avoid exposing sensitive internal details in error messages.
Examples demonstrate the intended wire format; they do not replace schema validation or server-side checks. Validate decoded input, enforce cross-parameter rules and authorization, and return the documented errors. Do not place credentials or other sensitive data in query strings: URLs can appear in logs, browser history, and other records.
Common Mistakes
- Listing a default without its trigger: Say whether it applies when a parameter is omitted, and distinguish omission from an empty value.
- Leaving arrays ambiguous:
tag=a&tag=b,tag=a,b, andtag[]=a&tag[]=bare different conventions. Show the one your API accepts. - Describing a conditional requirement only in an example: State the rule explicitly and validate it independently.
- Assuming a schema applies defaults automatically: Verify server behavior and generated client behavior separately.
- Ignoring duplicate or unknown parameters: Different parsers may handle duplicates differently; define and test your policy.
- Treating a correctly encoded URL as valid input: Encoding protects the structure of the request; it does not establish that a value is permitted or authorized.
Review Checklist
- Does every parameter have its exact name, type, required status, constraints, and meaning?
- Are defaults and the difference between omission and empty values explicit?
- Are repeatable parameters and duplicate scalar keys documented with wire-format examples?
- Are dependencies, exclusions, boundaries, and unknown-parameter behavior specified?
- Do examples demonstrate encoding, including literal delimiters and plus signs?
- Are validation and authorization enforced on the server, not merely described in the schema?
- Do documented errors match actual responses for representative invalid requests?
- Have the OpenAPI definition, server behavior, and generated clients been checked for consistency?
Conclusion
A good parameter reference is an executable contract in spirit: it tells clients what to send and what happens when a request is invalid. Pair clear examples and an accurate OpenAPI description with server-side validation and checks against real implementation behavior.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.