REST API Resource Naming and URL Design

Naming conventions for resources, relationships, nested endpoints, and clean URL design.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Naming conventions

Keep endpoint names predictable and uniform.

Use consistent casing in paths

Pick one URL style and use it consistently.

textANYrestpathskebab-case
text
/purchase-orders
/api-keys

Kebab-case is common in URLs because it is readable and avoids case-sensitivity surprises.

Avoid format suffixes in paths

Negotiate format via headers, not path suffixes.

textANYrestcontent-negotiationpaths
text
Prefer: GET /reports/123
Avoid:  GET /reports/123.json

Content negotiation and media types are usually cleaner than path-based format suffixes.

Name relationships clearly

Make related collections obvious.

textANYrestrelationshipsnested
text
GET /teams/{teamId}/members

A relationship collection should read clearly from left to right and preserve the domain meaning.

Keep nesting shallow

Prefer one or two levels of depth.

textANYrestnestingurls
text
Better: /orders/{orderId}/items
Avoid:  /customers/{customerId}/orders/{orderId}/items/{itemId}/notes

Deeply nested URLs become harder to maintain, document, and cache.

Expose canonical resource paths

Each resource should have an obvious direct URL.

textANYrestcanonicalresources
text
/orders/{orderId}
/order-items/{itemId}

Even if a resource is reachable through a nested route, it often helps to expose a canonical direct path for the item itself.

Path vs query parameters

Put identity in the path and modifiers in the query string.

Put resource identity in the path

Use the path for the primary resource being addressed.

httpANYrestpath-paramsidentity
http
GET /users/123

The path identifies the thing the request is about.

Use query parameters for filtering

Filter a collection with query fields.

httpANYrestqueryfiltering
http
GET /users?role=admin&status=active

Query parameters are a better fit for filtering, sorting, searching, pagination, and sparse fieldsets.

Use query parameters for field selection

Return only needed fields.

httpANYrestprojectionfields
http
GET /users/123?fields=id,name,email

Sparse fieldsets can reduce payload size and overfetching in large representations.

Use includes for related resources

Let clients opt into embedded relationships.

httpANYrestincludeembedding
http
GET /orders/ord_123?include=customer,items

Optional includes can reduce round trips while keeping the base response lightweight.

Recommended next

No recommendations yet.