When do you use path params vs query params vs the request body?
⚡ 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.