Path Parameters
What are path parameters in an API?
Path parameters are variable parts of a URL that identify a specific resource or route in a web application or API. In /products/123, 123 selects one product. They are also called path variables or route parameters.
How path parameters work in a URL path
A server matches the incoming URL against a route template.
- Define a template, such as
/products/{id}or/products/:id. - Receive a request such as
/products/123. - Match
123to the variable segment. - Validate and convert it, for example to an integer or UUID.
- Return the resource, or an appropriate error.
Path parameters vs. query parameters
Use the path for identity. Use query parameters for optional ways to refine a request.
| Path parameter | Query parameter |
|---|---|
| Inside the URL path | After ? |
/products/123 | /products?sort=price |
| Usually required for route matching | Usually optional for filters, search, sorting, or pagination |
| Changes the resource route and cache key | Changes request options and often the cache key |
When to use path parameters
Choose them when the value is part of the resource’s address.
- Unique IDs, such as
/orders/81. - Nested resources, such as
/users/42/orders. - Stable readable slugs, such as
/articles/path-parameters. - Action routes only when an HTTP method cannot express the action clearly.
- Keep optional URL parameters, such as page or filter choices, in the query string.
Practical limits and common mistakes
Small routing decisions prevent confusing API behavior.
- Register
/users/mebefore/users/{id}when the framework uses route order. - Do not make a path segment optional. Create a separate route or use a query parameter.
- URL-encode reserved characters and validate every value.
- Return 400 for an invalid format and 404 when a valid identifier has no matching resource.
- Avoid exposing secrets or inconsistent, overly deep nesting.
Path parameters in app development with Emergent
Clear route requirements help Emergent generate consistent frontend links, backend endpoints, validation, and tests for full-stack apps. Explore the Learn hub and broader glossary to plan routes with confidence. Build routes with clear resource paths using Emergent.
Frequently Asked Questions
Your Questions, Answered
Don't change this element unless you know what you are doing
What are path parameters in a REST API?
They are variable URL segments that identify a resource, such as /customers/42.
When should I use path parameters vs. query parameters?
Use path parameters for the resource being addressed. Use query parameters for optional filters, sorting, search, and pagination.
How do I pass a path parameter in a URL?
Replace the route placeholder with a value, such as changing /products/{id} to /products/123.
How do I send path parameters in Postman?
Enter the completed URL in the request field, or define a route variable and provide its value in Postman’s path variables editor.
What is the difference between a path parameter and a query parameter?
A path parameter is part of the route and usually identifies a resource. A query parameter follows ? and usually modifies or filters the request.
on Emergent today


