💡 If you like this website, please share it with your friends and network! 🚀
Back to All Questions
Question 20 of 100
Basic API Testing
Beginner

Q20: What is the Difference Between Query and Path Parameters?

🔀Core Concept

What is the Difference Between Query and Path Parameters?

Key Takeaways & Architecture Summary

  • Path Parameters identify a unique resource; Query Parameters filter the resource list.
  • Path parameters are separated by slashes (/); Query parameters start with a question mark (?).
  • Path parameters are mandatory for routing; Query parameters are optional.

Direct Answer Summary

Path Parameters are mandatory routing segments embedded in the URL path to locate a specific, unique resource instance. Query Parameters are optional key-value pairs appended to the URL end to filter, sort, or paginate resource collections.

⚠️ Senior Engineering Warning (Red Flag)

Avoid using query parameters to represent hierarchical parent-child relationships. E.g. use /blogs/12/comments, not /comments?blogId=12, as the former clearly representsComments as nested under Blog.

💡 STAR Architectural Explanation & Pro Tip

Correct design helps cache efficiency. Browsers and proxies cache resource paths individually, whereas query parameters can yield varying cache lookup hits depending on key order.

RestAssuredTest.java
Rest-Assured + Java
// ✅ Path parameter (Locates specific task 99)
// GET /api/v1/tasks/99

// ✅ Query parameter (Filters task collections by priority)
// GET /api/v1/tasks?priority=high