What is the difference between path parameters and query parameters?
Answer
Path parameters are part of the URL path and identify a specific resource: GET /users/42 — here 42 is the path parameter identifying a unique user. They are required and define the resource's identity. Query parameters come after the ? in the URL and provide additional input: GET /users?role=admin&sort=createdAt&limit=20. They are optional and used for filtering, sorting, pagination, and search. The rule of thumb: use path parameters for resource identity and query parameters for modifying how a resource collection is returned. Example: GET /products/{id} (path) vs GET /products?category=electronics&maxPrice=500 (query).
Previous
What are REST resource naming conventions?
Next
What are the most important HTTP request and response headers in REST APIs?
More REST API Design Questions
View all →- Beginner What is REST and what are its six architectural constraints?
- Beginner What are the main HTTP methods used in REST APIs and what do they do?
- Beginner What is idempotency and which HTTP methods are idempotent?
- Beginner What are the most important HTTP status codes in REST APIs?
- Beginner What are REST resource naming conventions?