# Resource naming and URL design conventions

> How do you design clean REST URLs? What are the rules for naming resources, nesting, and actions that do not fit CRUD?

Canonical: https://www.internhack.in/learn/interview/api-design-interview/api-resource-naming
Last updated: 2026-11-28

Difficulty: Beginner

## Question

How do you design clean REST URLs? What are the rules for naming resources, nesting, and actions that do not fit CRUD?

## Answer

Let me start with the mental model: a URL is an address for a thing, not a command. If you think of a library, the URL points to a shelf or a book, and the HTTP method tells the librarian what to do with it. That is why we prefer nouns in paths and let GET, POST, PUT, PATCH and DELETE carry the verb.

Use plural nouns for collections: /orders for the collection and /orders/42 for one order. Plural everywhere is more consistent than mixing singular and plural. Use lowercase and hyphens for multi-word segments, such as /delivery-partners, since URLs are case sensitive in the path and underscores can be hidden by link underlining. Avoid file extensions and avoid trailing slashes inconsistently; pick one and redirect the other.

Bad: /getOrder?id=42, /createUser, /deleteOrder/42. Good: GET /orders/42, POST /users, DELETE /orders/42. The bad forms tunnel verbs through URLs, which duplicates what HTTP already gives you and breaks caching and tooling expectations.

Express hierarchy through nesting only when a child cannot exist without its parent: /restaurants/9/menu-items or /orders/42/items. Keep nesting to two levels at most. Deep chains like /users/1/orders/2/items/3/reviews/4 become brittle and hard to document. A good compromise is to expose the child at the top level as well, so /reviews/4 works, and use query filters such as /reviews?order_id=2 for relationships.

Use query strings for filtering, sorting, pagination and searching, not for identity: /orders?status=paid&sort=-created_at. Path parameters identify a specific resource; query parameters shape a collection view.

Now the awkward part: actions that are not clean CRUD. Cancel an order, publish a post, retry a payment. There are three accepted approaches. First, model the state change as a field update: PATCH /orders/42 with status cancelled. This is simple but hides business rules. Second, model the action as a sub-resource, POST /orders/42/cancellation, which creates a cancellation record that can itself hold reason and timestamps. Third, use a controller-style verb segment such as POST /orders/42/cancel. Stripe and Google both use this pragmatic verb form for genuine actions. The interviewer mostly wants to see that you choose deliberately and stay consistent.

Other conventions worth mentioning: do not expose auto-increment integers if enumeration is a concern; use opaque ids or UUIDs. Keep the URL stable when the implementation changes; a URL is a public contract. Do not put secrets like API keys or tokens in the URL because they land in logs and browser history. And version the API in a predictable place such as /v1.

One more edge case: singleton resources. The current user's profile can be /me or /users/me, which is friendlier than forcing the client to know its own id. Search that crosses resource types is often a top level /search endpoint.

If you remember one line for the interview: nouns for resources, HTTP methods for verbs, query params for views, and a deliberate, consistent pattern for the few things that are truly actions.

## Code examples

### Good vs bad URL design

```
# Avoid
POST /createOrder
GET  /getOrdersByUser?userId=7
POST /deleteOrder/42

# Prefer
POST   /v1/orders
GET    /v1/orders?user_id=7&status=paid&sort=-created_at
DELETE /v1/orders/42
POST   /v1/orders/42/cancel
```

Resource nouns plus methods for CRUD, and a single explicit action sub-path for cancel.

## Key points

- Plural nouns, lowercase, hyphen separated.
- Limit nesting to two levels and offer top level access for children.
- Query params filter and sort; path params identify.
- Genuine actions can use POST on a verb sub-path or a sub-resource.
- Never put secrets in URLs.

## Common follow-up questions

- How would you design the URL to cancel an order versus updating its address?
- Should ids be sequential integers or UUIDs?
- How do you design a search endpoint that spans several resources?

## Interview tips

- Show the bad-to-good rewrite out loud; it is very convincing.
- Acknowledge that action endpoints are a debated area instead of claiming one true way.

## Concepts covered

URL design, resources, nouns, nesting

Previous: [REST architectural constraints explained](https://www.internhack.in/learn/interview/api-design-interview/api-rest-constraints) · Next: [HTTP methods: safe vs idempotent](https://www.internhack.in/learn/interview/api-design-interview/api-http-methods-idempotency) · [All of API Design](https://www.internhack.in/learn/interview/api-design-interview)

## More API Design questions

- [PUT vs PATCH vs POST: when to use which](https://www.internhack.in/learn/interview/api-design-interview/api-put-vs-patch-vs-post)
- [Choosing the right HTTP status codes](https://www.internhack.in/learn/interview/api-design-interview/api-status-codes)
- [Designing error responses with RFC 9457 problem details](https://www.internhack.in/learn/interview/api-design-interview/api-error-format-problem-details)
- [Pagination: offset vs cursor (keyset) trade-offs](https://www.internhack.in/learn/interview/api-design-interview/api-offset-vs-cursor-pagination)
- [Filtering, sorting, searching and field selection](https://www.internhack.in/learn/interview/api-design-interview/api-filtering-sorting-fields)
- [API versioning strategies and trade-offs](https://www.internhack.in/learn/interview/api-design-interview/api-versioning)

## Related

- [Learn](https://www.internhack.in/learn)
- [Interview Prep](https://www.internhack.in/learn/interview)
- [API Design](https://www.internhack.in/learn/interview/api-design-interview)
