REST API Design: Conventions and Best Practices
Learn REST API design conventions including resource naming, HTTP methods, status codes, pagination, filtering, versioning, and error handling best practices.
REST API conventions are the shared rules for resource naming, HTTP methods, status codes, and pagination that make an API predictable to use. A well-designed REST API feels intuitive — you can guess the endpoints, predict the response structure, and handle errors without constantly checking the docs. A poorly designed one forces you to memorize arbitrary conventions, decode cryptic error messages, and work around inconsistencies.
The difference comes down to following established conventions. This guide covers the design decisions you will face when building a REST API and the conventions that make your API predictable and pleasant to use.
Resource Naming
URLs identify resources. Get the naming right and your API is half-documented already.
Use Nouns, Not Verbs
Resources are things, not actions. The HTTP method provides the verb.
# Good
GET /api/users
POST /api/users
GET /api/users/123
PUT /api/users/123
DELETE /api/users/123
# Bad
GET /api/getUsers
POST /api/createUser
POST /api/deleteUser/123
Use Plural Nouns
Be consistent — use plurals for all collection resources.
# Good
/api/users
/api/users/123
/api/projects
/api/projects/456/tasks
# Avoid mixing
/api/user (singular)
/api/projects (plural)
Nest for Relationships
Express parent-child relationships through URL nesting, but keep nesting shallow — one or two levels maximum.
# Good — clear relationship
GET /api/projects/456/tasks
GET /api/projects/456/tasks/789
# Too deep — hard to construct and read
GET /api/organizations/1/teams/2/projects/3/tasks/4/comments/5
For deeply nested resources, promote them to top-level with a filter:
# Better — flat with a filter
GET /api/comments?task_id=4
Naming Conventions
- Use lowercase:
/api/users, not/api/Users - Use hyphens for multi-word resources:
/api/project-members, not/api/projectMembersor/api/project_members - Avoid trailing slashes:
/api/users, not/api/users/ - Avoid file extensions:
/api/users, not/api/users.json
HTTP Methods
Each HTTP method has a defined semantic:
| Method | Purpose | Idempotent | Safe | Request Body |
|---|---|---|---|---|
| GET | Retrieve resource(s) | Yes | Yes | No |
| POST | Create a resource | No | No | Yes |
| PUT | Replace a resource entirely | Yes | No | Yes |
| PATCH | Partially update a resource | No* | No | Yes |
| DELETE | Remove a resource | Yes | No | Optional |
*PATCH is not guaranteed to be idempotent, but you can design it to be.
GET
Retrieves data without side effects. Never use GET to modify data.
GET /api/users/123 HTTP/1.1
HTTP/1.1 200 OK
{
"id": 123,
"name": "Alice",
"email": "alice@example.com",
"created_at": "2026-01-15T10:30:00Z"
}
POST
Creates a new resource. Returns the created resource with its server-generated ID.
POST /api/users HTTP/1.1
Content-Type: application/json
{
"name": "Bob",
"email": "bob@example.com"
}
HTTP/1.1 201 Created
Location: /api/users/456
{
"id": 456,
"name": "Bob",
"email": "bob@example.com",
"created_at": "2026-09-29T14:00:00Z"
}
PUT vs PATCH
PUT replaces the entire resource. Any fields you omit are set to null or defaults.
PATCH updates only the fields you include. Other fields remain unchanged.
# PUT — full replacement
PUT /api/users/123 HTTP/1.1
{
"name": "Alice Smith",
"email": "alice.smith@example.com",
"role": "admin"
}
# PATCH — partial update
PATCH /api/users/123 HTTP/1.1
{
"name": "Alice Smith"
}
Use PATCH for most update operations. PUT is appropriate when the client has the complete resource and wants to replace it entirely.
DELETE
Removes a resource. Return 204 (No Content) on success.
DELETE /api/users/123 HTTP/1.1
HTTP/1.1 204 No Content
Deleting a resource that does not exist should return 404, not an error. Alternatively, some APIs return 204 for idempotency — the end state is the same either way.
Pagination
Any endpoint that returns a list must support pagination. Unbounded lists break as your data grows.
Offset-Based Pagination
The simplest approach. Works well for most use cases.
GET /api/users?page=2&per_page=25 HTTP/1.1
HTTP/1.1 200 OK
{
"data": [ ... ],
"pagination": {
"page": 2,
"per_page": 25,
"total": 150,
"total_pages": 6
}
}
Add Link headers for discoverability:
Link: </api/users?page=1&per_page=25>; rel="first",
</api/users?page=1&per_page=25>; rel="prev",
</api/users?page=3&per_page=25>; rel="next",
</api/users?page=6&per_page=25>; rel="last"
Limitation: Offset pagination performs poorly on large datasets. Skipping 100,000 rows is expensive for the database.
Cursor-Based Pagination
Better for large datasets and real-time data. The cursor is an opaque token pointing to a position in the result set.
GET /api/events?limit=25&after=eyJpZCI6MTAwfQ HTTP/1.1
HTTP/1.1 200 OK
{
"data": [ ... ],
"pagination": {
"has_more": true,
"next_cursor": "eyJpZCI6MTI1fQ"
}
}
Cursor pagination does not support jumping to arbitrary pages, but it handles insertions and deletions gracefully — new items appearing between page loads do not shift your position.
Filtering, Sorting, and Searching
Filtering
Use query parameters for filtering:
GET /api/users?role=admin&status=active
GET /api/tasks?priority=high&assignee=123
GET /api/orders?created_after=2026-01-01&created_before=2026-06-30
Sorting
Use a sort parameter. Prefix with - for descending order:
GET /api/users?sort=name # Ascending by name
GET /api/users?sort=-created_at # Descending by creation date
GET /api/users?sort=role,-name # Sort by role, then name descending
Searching
For full-text search, use a q or search parameter:
GET /api/users?q=alice
GET /api/articles?search=css+grid
Field Selection
Let clients request only the fields they need:
GET /api/users?fields=id,name,email
GET /api/users/123?fields=id,name,avatar_url
This reduces payload size and can improve query performance.
API Versioning
Your API will change over time. Versioning lets you evolve without breaking existing consumers.
URL Path Versioning
The most common and most explicit approach:
GET /api/v1/users
GET /api/v2/users
Pros: Clear, easy to understand, easy to route. Cons: Purists argue it violates REST (the URL identifies the resource, not the version).
Header Versioning
Use a custom header or the Accept header:
GET /api/users HTTP/1.1
Accept: application/vnd.myapi.v2+json
Pros: Clean URLs. Cons: Less discoverable, harder to test in a browser.
Query Parameter Versioning
GET /api/users?version=2
Pros: Simple. Cons: Easy to forget, mixes API concerns with resource queries.
Recommendation
Use URL path versioning (/v1/, /v2/). It is the most widely used, the most discoverable, and the easiest to implement. Only increment the major version when you make breaking changes.
Error Handling
Consistent error responses are just as important as consistent success responses. Use our HTTP error lookup as a reference for choosing the right status code.
Error Response Structure
{
"error": {
"code": "validation_error",
"message": "The request body contains invalid data",
"details": [
{
"field": "email",
"message": "Must be a valid email address"
},
{
"field": "age",
"message": "Must be a positive integer"
}
]
},
"request_id": "req_abc123"
}
Consistent Status Codes
Map operations to status codes consistently:
| Operation | Success Code | Common Error Codes |
|---|---|---|
| GET (found) | 200 | 404 |
| GET (list) | 200 | 400 (bad filter params) |
| POST (created) | 201 | 400, 409, 422 |
| PUT/PATCH | 200 | 400, 404, 409, 422 |
| DELETE | 204 | 404 |
Response Envelope
Wrapping responses in a consistent envelope makes client-side handling predictable:
{
"data": {
"id": 123,
"name": "Alice"
},
"meta": {
"request_id": "req_abc123",
"timestamp": "2026-09-29T14:00:00Z"
}
}
For collections:
{
"data": [
{ "id": 1, "name": "Alice" },
{ "id": 2, "name": "Bob" }
],
"pagination": {
"page": 1,
"per_page": 25,
"total": 2
},
"meta": {
"request_id": "req_def456"
}
}
Use the JSON formatter to inspect and validate your API responses during development.
Additional Conventions
Use ISO 8601 for Dates
{
"created_at": "2026-09-29T14:30:00Z",
"updated_at": "2026-09-29T15:45:00Z"
}
Always use UTC. Let the client convert to local time.
Use Consistent Casing
Pick one and stick with it for all response fields:
- snake_case:
created_at,user_id(popular in Ruby, Python, Go APIs) - camelCase:
createdAt,userId(popular in JavaScript, Java APIs)
Include Related Resources
Use include or expand parameters to embed related resources:
GET /api/orders/123?include=items,customer
{
"data": {
"id": 123,
"total": 99.99,
"customer": {
"id": 456,
"name": "Alice"
},
"items": [
{ "id": 1, "product": "Widget", "quantity": 2 }
]
}
}
Rate Limiting
Include rate limit information in response headers:
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 950
X-RateLimit-Reset: 1625097600
HATEOAS (Optional)
Include links for discoverability:
{
"data": {
"id": 123,
"name": "Alice"
},
"links": {
"self": "/api/users/123",
"projects": "/api/users/123/projects",
"avatar": "/api/users/123/avatar"
}
}
Summary
Good REST API design follows conventions that make the API predictable. Use plural nouns for resources, let HTTP methods define the action, return appropriate status codes, paginate lists, and version your API through the URL path. Consistent error responses with clear codes and messages help developers debug issues quickly. These are not rigid rules — they are conventions that reduce the cognitive load for everyone who uses your API.
Turn a click-through into an interactive demo
AtriumKit records your web app once in Chrome and turns every click into a step of a demo you can embed or share. There’s a free plan.
Try AtriumKit free
Comments