When do you use path params vs query params vs the request body?
Reviewed by Gurusankar M.
Short Answer
Path params identify a resource (/orders/42). Query params filter/sort/paginate or pass optional modifiers (?status=open&page=2). The body carries the resource payload for POST/PUT/PATCH. Don't put sensitive data in the URL — it's logged and cached.
On this page
Concept Made Simple
Coffee Chat Question
“When do you use path params vs query params vs the request body?”
Remember It Faster
Mind Map Answer
- Path
- identify a resource: /orders/42
- Query
- filter/sort/paginate: ?status=open
- Body
- payload for create/update
Think Beyond the Expected
What If?
Why shouldn't you pass an API token or password as a query parameter?
URLs (including query strings) are logged by servers/proxies, stored in browser history, and may be cached or appear in Referer headers — leaking the secret. Put credentials in the Authorization header (or body over HTTPS), never the URL.
Real World
Leaking tokens via query strings into access logs is a real security finding; the convention 'path = identity, query = filters, header = auth, body = payload' keeps APIs clean and safe.
Interviewer's Expectation
Keywords they're listening for:
- path identifies resource
- query filters/optional
- body = payload
- no secrets in URL
- URLs are logged/cached
Common Mistakes
- Secrets/PII in query strings
- Filters in the path instead of query
- GET with a body (poorly supported)
Best Practices
- Path = identity, query = filters, body = payload
- Auth via Authorization header
- Keep URLs free of sensitive data
Follow-up Questions
- Where do you put a date range — query or body?
- When is a POST with a body acceptable for a 'search'?
- How long can a URL safely be?
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: HTTP Methods (REST APIs) Interview question: "When do you use path params vs query params vs the request body?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
Affiliate links
Tools for Your Developer Workspace
Equipment for a comfortable, productive setup.
As an Amazon Associate I earn from qualifying purchases.
- MonitorView on Amazon : BenQ EW2790U 27-inch Monitor (opens in a new tab)
BenQ EW2790U 27-inch Monitor
- LaptopView on Amazon : Acer Aspire One Laptop (opens in a new tab)
Acer Aspire One Laptop
- Office ChairView on Amazon : Wakefit Gravita Ergonomic Office Chair (opens in a new tab)
Wakefit Gravita Ergonomic Office Chair