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.
βCoffee Chat Question
Concept Made Simple
βWhen do you use path params vs query params vs the request body?β
π§ Mind Map Answer
Remember It Faster
π₯What If?
Think Beyond the Expected
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:
β οΈ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
- 1Where do you put a date range β query or body?
- 2When is a POST with a body acceptable for a 'search'?
- 3How long can a URL safely be?
π§©Related Technologies
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?
β Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission β at no extra cost to you. It helps keep Full Stack Interview Guru free.