Skip to content

Endpoint Design

Resource naming, URL structure, HTTP methods, and query parameter conventions for REST APIs.

REST APIs express operations as HTTP methods acting on resources. The URL names the thing; the method says what to do with it. Keep those two concerns cleanly separated and endpoint design becomes mechanical.

Resource naming

Resources are nouns, not verbs. The method already carries the action.

Instead of Use
POST /createUser POST /users
GET /getUserById GET /users/{id}
DELETE /removePost DELETE /posts/{id}

Plural nouns. Collections are sets of things: /users, /orders, /invoices. A single resource is an item within that collection: /users/{id}.

kebab-case in path segments. URL paths are case-insensitive in practice and hyphens read more naturally than underscores in addresses: /blog-posts, not /blog_posts or /blogPosts. JSON field names remain snake_case; the two conventions coexist, they apply to different layers.

No file extensions. Never expose .json or .xml suffixes in paths. Content negotiation belongs in the Accept header, not the URL.

URL structure

https://api.example.com/v1/{resource}
https://api.example.com/v1/{resource}/{id}
https://api.example.com/v1/{resource}/{id}/{sub-resource}

Nest sub-resources at most one level deep. If you need to go deeper, the resource has drifted and probably deserves its own top-level path. /organizations/{id}/members is fine; /organizations/{id}/teams/{id}/members/{id}/roles is a sign to redesign.

For the format of {id} values (the choice between UUIDs, prefixed IDs, and the two-column internal/external pattern), see Identities.

Standard CRUD mapping

Method Path Semantics
GET /users List users (paginated)
POST /users Create a user
GET /users/{id} Get a single user
PUT /users/{id} Replace a user (full update)
PATCH /users/{id} Partial update
DELETE /users/{id} Delete a user

POST on a collection returns 201 Created with a Location header pointing to the new resource:

HTTP/1.1 201 Created
Location: /users/f47ac10b-58cc-4372-a567-0e02b2c3d479
Content-Type: application/json

Clients that only need the URL of the new resource can read Location without parsing the body. Use Link for hypermedia relationships (pagination cursors, related resources), not for pointing to a newly created resource.

Use PUT only when the client sends the complete representation. If the client can omit fields it doesn’t want to change, use PATCH. Most update operations in practice are partial, so PATCH is the default choice.

DELETE returns 204 No Content with an empty body, not 200 with the deleted resource and not 404 if the resource is already gone (idempotent deletes are more useful to clients).

Non-CRUD actions

Some operations don’t map cleanly to a single resource mutation. Favor a sub-resource or a state transition rather than a verb endpoint:

POST /users/{id}/password-reset
POST /invoices/{id}/void
POST /subscriptions/{id}/cancel

Treat the action as a resource being created on the parent. This keeps the method (POST) consistent and makes the intent obvious from the URL.

Query parameters

Query parameters filter, sort, shape, and paginate collection responses. Keep names short, lowercase, and snake_case.

Filtering

Use the field name directly as the parameter name for equality filters:

GET /users?status=active
GET /orders?user_id=f47ac10b-58cc-4372-a567-0e02b2c3d479
GET /posts?author_id=6ba7b810-9dad-11d1-80b4-00c04fd430c8&status=published

For range filters, use {field}_before / {field}_after:

GET /orders?created_after=2024-01-01T00:00:00.000Z
GET /orders?created_before=2024-06-01T00:00:00.000Z&status=shipped

Avoid filter namespacing schemes like filter[field]=value or q[field_eq]=value unless your client SDK generates them; they’re hard to type and don’t improve on the flat form in practice.

Sorting

A single sort parameter accepting a comma-separated list of field names. Prefix with - for descending:

GET /users?sort=last_name          # ascending by last_name
GET /users?sort=-created_at        # descending (newest first)
GET /orders?sort=-created_at,total # newest first, then by total ascending

Always define a stable default sort order (typically -created_at) and document it, because pagination cursors depend on consistent ordering.

Sparse fieldsets

If clients frequently need only a subset of fields, accept a fields parameter:

GET /users?fields=id,email_address,created_at

Omit this unless you have real evidence that response size is a problem. Sparse fieldsets complicate server logic, caching, and SDK generation; the bandwidth savings rarely justify the cost for typical payloads.

Pagination parameters

See Pagination for the full pattern. The parameters themselves follow the same naming rules:

GET /users?limit=20&cursor=eyJpZCI6IjEyMyJ9

limit and cursor are reserved parameter names; don’t use them for anything else.

Type to search…

↑↓ navigate↵ selectEsc close