Product
Enterprise
Solutions
DocumentationPricing
Resources
Book a DemoSign InGet Started
Product
Solutions
Solutions
Blog |How API Parameters Work: Query, Path, Header, and Body

How API Parameters Work: Query, Path, Header, and Body

API Design  |  Sep 19, 2025  |  8 min read  |  By Savan Kharod  |  Reviewed by David Blažević

Summarize with
How API Parameters Work: Query, Path, Header, and Body image

Savan Kharod works on demand generation and content at Treblle, where he focuses on SEO, content strategy, and developer-focused marketing. With a background in engineering and a passion for digital marketing, he combines technical understanding with skills in paid advertising, email marketing, and CRM workflows to drive audience growth and engagement. He actively participates in industry webinars and community sessions to stay current with marketing trends and best practices.

API parameters are the inputs that shape an HTTP request. They filter lists, identify resources, carry metadata, and submit payloads. In practice, parameters show up in four places: query, path, headers, and body, and each has a clear job. 

This guide explains when to use each, with concise examples and code. You’ll also see how Treblle surfaces query parameters, path parameters, header parameters, and request body fields automatically in one place for faster debugging and API logging.

Let’s get started. 

Need real-time insight into how your APIs are used and performing?

Treblle helps you monitor, debug, and optimize every API request.

Explore Treblle
CTA Image

Need real-time insight into how your APIs are used and performing?

Treblle helps you monitor, debug, and optimize every API request.

Explore Treblle
CTA Image

Query Parameters (?key=value)

Query parameters live in the URI’s query component (the part after ?) and are best used for filtering, searching, sorting, and API pagination. They refine a resource without changing its identity, for example, listing only a subset of /products. The query component is formally defined by RFC 3986 (§3.4), and clients/servers should percent-encode reserved characters per the URI rules. 

Example

GET /products?category=shoes&limit=10

In code (Express/Node.js)

app.get('/products', (req, res) => {
  const { category, limit = '10' } = req.query;        // e.g., "shoes", "10"
  const pageSize = Number(limit) || 10;
  const items = fetchProducts({ category, limit: pageSize }); // your data access
  res.json({ items, category, limit: pageSize });
});

Expected JSON

{
  "items": [/* ... */],
  "category": "shoes",
  "limit": 10
}

 Notes for implementation

  • Prefer query params for optional inputs; keep path segments for resource identity (e.g., /users/{id}). OpenAPI explicitly models query parameters and supports array/object serialization patterns when needed. 

  • In browser/JS code, URLSearchParams provides a clean API to read or build query strings (new URL(url).searchParams).

How Treblle logs them

Treblle records the full request context, including method, URL, and query parameters, and shows them in the request detail view (with sensitive values masked). This gives you real-time visibility into exactly which filters or pagination inputs were used, alongside status, latency, and response data.

Path Parameters (/resource/:id)

Path parameters identify a specific resource (or nested resource) as part of the URL path. In RESTful design, use path params for resource identity and reserve query params for filtering/sorting. In OpenAPI, these are modeled as in: path and typically appear as placeholders like /users/{id}.

Example

GET /users/123

Here, 123 is the resource identifier embedded in the path. Per the URI spec (RFC 3986), the path is the hierarchical component that locates a resource; individual segments (like users and 123) are parsed left-to-right.

In code (Express/Node.js)

app.get('/users/:id', (req, res) => {
  const { id } = req.params;               // e.g., "123"
  const user = getUserById(id);
  if (!user) return res.status(404).json({ error: 'Not found' });
  res.json(user);
});

Express exposes route parameters via req.params, keyed by the :name in the route.

In code (Flask/Python)

@app.get("/users/<int:id>")
def get_user(id: int):
    user = get_user_by_id(id)
    return ({"error": "Not found"}, 404) if user is None else userdef get_user(id: int):

Flask “variable rules” capture values from the URL and pass them to the view function (with optional converters like int).

Always use path params for identity (e.g., /orders/42), not for optional filters; keep those in the query string. Model them explicitly in your OpenAPI so clients and SDKs understand required path variables.

Treblle: how it’s logged

  • Treblle auto-indexes your API endpoints and ties each incoming request to its endpoint path, so you can drill into /users/{id} traffic and see the exact request that hit /users/123. From the Recent Requests feed, opening a request shows the full URL, method, status, timing, and request/response details in one view.

Need real-time insight into how your APIs are used and performing?

Treblle helps you monitor, debug, and optimize every API request.

Explore Treblle
CTA Image

Need real-time insight into how your APIs are used and performing?

Treblle helps you monitor, debug, and optimize every API request.

Explore Treblle
CTA Image

Header Parameters (Authorization, Content-Type)

Header parameters carry metadata that shapes how requests are processed and how responses are interpreted. They’re not part of the URL or body; they travel alongside the message to declare formats, credentials, and client context. Key API headers include:

  • Content-Type — tells the server how to parse the body (e.g., application/json). The response mirrors this via Content-Type so clients know how to parse it.

  • Accept — lets clients state which media types they can handle; the server performs content negotiation and replies accordingly.

  • Authorization — carries credentials. Common schemes include Bearer (OAuth 2.0), Basic, or custom API keys. Always send over HTTPS to protect tokens in transit.

  • User-Agent — identifies the calling client; useful for analytics and troubleshooting. 

In code (Express/Node.js)

app.post('/orders', (req, res) => {
  const contentType = req.get('Content-Type');          // e.g., application/json
  const accept = req.get('Accept');                     // e.g., application/json
  const auth = req.get('Authorization');                // e.g., Bearer <token>
  const ua = req.get('User-Agent');
  // validate headers, then handle request...
  res.set('Content-Type', 'application/json');          // declare response type
  return res.json({ ok: true, contentType, accept, ua, hasAuth: Boolean(auth) });
});

Tip: Treat header validation as part of your API contract. Enforce HTTPS and verify auth headers on every API endpoint to avoid credential leakage and downgrade attacks. 

How Treblle logs header parameters

Treblle captures request and response headers automatically on every call in the dashboard, allowing you to inspect Content-Type, Accept, Authorization, CORS, and custom headers per request. Sensitive values (including authorization credentials) are masked before they leave your server, preserving structure while protecting secrets; the masking list is configurable across official SDKs (and in custom SDKs) to fit your policies. 

Body Parameters (JSON, form data)

Use the request body to send structured data for create/update operations—typically with POST, PUT, or PATCH. The server decides how to parse the body based on the Content-Type header. In practice, APIs default to application/json for machine-readable payloads; web forms often use application/x-www-form-urlencoded (simple key–value pairs) or multipart/form-data (files + fields).

JSON payloads (most common)

Example

POST /orders
Content-Type: application/json
{
  "customerId": "c_7812",
  "items": [
    { "sku": "A12-9", "qty": 2 },
    { "sku": "B44-1", "qty": 1 }
  ],
  "paymentMethod": "card"
}

Express (Node.js)

import express from "express";
const app = express();
 
app.post("/orders", express.json(), (req, res) => {
  const order = createOrder(req.body); // your domain logic
  res.status(201).json(order);
});

express.json() parses JSON bodies and exposes them as req.body. Choose JSON for structured, language-agnostic data.

Form submissions & file uploads

Use application/x-www-form-urlencoded for simple form key–value pairs and multipart/form-data when uploading files (or mixing files and text). Client-side, the FormData API builds a multipart/form-data body that fetch() or XHR can send.

Browser (FormData)

const fd = new FormData();
fd.append("username", "savan");
fd.append("avatar", fileInput.files[0]); // a File object
 
await fetch("/profile", { method: "POST", body: fd }); // multipart/form-data

FormData serializes fields/files using multipart/form-data; the server must use a multipart parser to read them.

Tips

  • Set Content-Type correctly (application/json, application/x-www-form-urlencoded, or multipart/form-data) so servers and clients parse bodies reliably.

  • Prefer JSON for API-to-API communication; use multipart only when files are involved.

  • Validate and size-limit bodies server-side to prevent abuse and improve error clarity. (General best practice.)

How Treblle logs body parameters

Treblle captures the full request body alongside method, URL, headers, and query/path parameters in real time—masking sensitive fields by default. In the dashboard, you’ll see the parsed body (JSON or form data), timing, status, and size, which makes debugging malformed JSON, missing fields, or upload issues straightforward. Masking is configurable per SDK. 

Need real-time insight into how your APIs are used and performing?

Treblle helps you monitor, debug, and optimize every API request.

Explore Treblle
CTA Image

Need real-time insight into how your APIs are used and performing?

Treblle helps you monitor, debug, and optimize every API request.

Explore Treblle
CTA Image

Why Logging API Parameters Matters

Robust API logging—including query parameters, path parameters, header parameters, and request body fields—turns guesswork into diagnosis. When a call fails or behaves oddly, having the full parameter set alongside method, URL, status, and timing lets you reproduce the request, spot malformed inputs, and resolve issues quickly.

This is the essence of actionable observability and a core reason API logs exist.

It’s also a security and compliance requirement. Well-designed logs provide traceability (who did what, when) without exposing secrets. Follow OWASP guidance to avoid logging sensitive data (e.g., auth tokens, credentials) and to structure logs so incidents can be investigated.

Many regimes (e.g., PCI DSS 4.0) also mandate retention and accessibility of audit trails—plan for secure storage, access controls, and sensible retention windows.

For consistency across services, align logs with OpenTelemetry semantic conventions. Capturing standard HTTP attributes (method, target URL, status, user agent, selected headers) makes it easier to correlate parameters with traces and metrics across your stack.

Treblle automatically captures complete request context—method, URL, query/path parameters, headers, and body—and presents it in a real-time dashboard. Sensitive values are masked by default, so you see presence and structure without leaking secrets. This makes it straightforward to debug missing/incorrect parameters, auth failures, CORS issues, or rate-limit misconfigurations while maintaining a defensible audit trail. 

Conclusion

API parameters are the contract surface of every call: query refines a resource, path identifies it, API headers carry metadata and security context, and the request body delivers structured payloads. OpenAPI formalizes this split, parameters live in query/path/header while bodies use requestBody, and URI rules (RFC 3986) define how the query component behaves, so clients and servers interpret requests consistently.

In practice, reliability comes from visibility. Log parameters alongside method, URL, status, and timing; follow OWASP guidance to avoid leaking secrets; and standardize attributes so telemetry and traces are comparable across services.

Treblle makes that operational: it captures each request’s full context, query/path parameters, headers (with masking), and bodies, inside a real-time “Recent Requests” view, so you can spot malformed inputs, auth issues, or CORS/rate-limit problems fast, without building custom logging.

If you need stricter controls, the SDKs let you customize what’s masked before data ever leaves your server. 

Need real-time insight into how your APIs are used and performing?

Treblle helps you monitor, debug, and optimize every API request.

Explore Treblle
CTA Image

Need real-time insight into how your APIs are used and performing?

Treblle helps you monitor, debug, and optimize every API request.

Explore Treblle
CTA Image

Related Articles

How to Get Complete API Visibility in MuleSoft with Treblle's Auto-Discovery coverAPI Design

How to Get Complete API Visibility in MuleSoft with Treblle's Auto-Discovery

MuleSoft APIs often sprawl across environments and business groups, leaving teams blind to what’s running. Treblle’s Auto-Discovery app solves this with a full API inventory, monitoring insights, and data-driven visibility.

What is an API Endpoint? A Beginner’s Guide coverAPI Design

What is an API Endpoint? A Beginner’s Guide

API endpoints are the access points where clients interact with your API. They define how data is requested, updated, or deleted. In this guide, we’ll break down what endpoints are, how they work, and how to design and manage them effectively as your API grows.

How to Choose Between API Polling and Webhooks (With Go Code Examples) coverAPI Design

How to Choose Between API Polling and Webhooks (With Go Code Examples)

When building apps that rely on external data, choosing how to receive updates is crucial. In this article, we compare API polling and webhooks, explain when to use each, and walk through practical Go examples to help you implement the right approach.

© 2025 Treblle. All Rights Reserved.
GDPR BadgeSOC2 BadgeISO BadgeHIPAA Badge