🔥 Firehook

Blog · api rest

REST resource and URL design: naming, hierarchies, and consistency

Design REST resources and URLs that scale: stable naming, shallow hierarchies, and predictable patterns clients can trust.

Isometric API gateway with clean connections, representing resource-centric URL design

Name resources, not actions

REST URLs should describe things. Start with nouns that reflect the domain: `/users`, `/devices`, `/orders`. This keeps the API intuitive and stable.

Actions belong to HTTP verbs, not to the path. `DELETE /orders/987` is clearer than `/orders/987/cancel`.

Choose a consistent pluralization

Most APIs use plural nouns for collections (`/users`) and a single ID for the item (`/users/123`). This is easy to learn and widely accepted.

The key is consistency. If you decide to use singular nouns, do it everywhere.

Keep hierarchies shallow

Nested paths express relationships, like `/users/123/orders`. This is fine when the child is strongly tied to the parent.

Avoid deep nesting. More than two levels creates coupling and makes URLs fragile when your model evolves.

Use query parameters for filters

Filtering, sorting, and pagination belong in query parameters: `/orders?status=paid&sort=-created_at&page=2`.

This keeps paths focused on identity and lets you extend filters without breaking clients.

Pick a casing convention

URLs should follow a single casing style. Kebab-case is common and readable. Query parameters are often snake_case.

The exact choice matters less than consistency. Inconsistent casing slows down integrations.

Design for change

Your API will evolve. Avoid encoding internal details like table names or service boundaries into URLs.

Use domain language that stays stable as your backend changes. This makes refactors less painful.

Examples that scale

A clean design: `/devices`, `/devices/{id}`, `/devices/{id}/state`, `/alerts`. Each endpoint represents an object with a clear lifecycle.

When you add features, reuse the same patterns. Consistency is what makes a REST API feel professional.

FAQ

Should REST URLs use verbs?
Generally no. Use nouns for resources and let HTTP verbs express the action.
How deep should resource hierarchies go?
Keep them shallow. Two levels are usually enough; deeper hierarchies increase coupling.
Is it okay to use IDs or slugs?
Both work. IDs are stable, slugs are readable. Choose one or support both with clear rules.
Path vs query parameters?
Use paths for identity and query params for filtering, sorting, or pagination.
How do I model relationships?
Use nested paths sparingly. If it grows deep, consider top-level endpoints with filters.