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).