# Resource-Oriented REST APIs

> Design JSON-over-HTTP APIs around resources, methods and status codes that clients can predict. Free notes, key concepts, resources and a mini project.

Canonical: https://www.internhack.in/roadmaps/tracks/backend/rest-api-design
Last updated: 2026-11-28

Design JSON-over-HTTP APIs around resources, methods and status codes that clients can predict.

Beginner · about 8 hours · difficulty 2/5

Learn first: [HTTP in Depth](https://www.internhack.in/roadmaps/tracks/backend/http-protocol)

**REST** is an architectural style where your API exposes **resources** (users, orders, invoices) at URLs and clients act on them with standard HTTP methods. Most public and internal web APIs are "RESTful" JSON APIs, even if few follow every constraint of the original definition.

### Designing resources

- Use nouns, plural collections: `GET /orders`, `GET /orders/42`, `POST /orders`, `PATCH /orders/42`, `DELETE /orders/42`.
- Nest only for clear ownership: `GET /users/7/orders`. Avoid deep nesting.
- For actions that do not map to CRUD, use a sub-resource: `POST /orders/42/cancel`.
- Return the right status: 201 with a `Location` header after create, 204 for no content, 404 for missing, 409 for conflicts, 422 for validation errors.

### Consistent payloads

Pick a JSON style (camelCase or snake_case) and stick to it. Use ISO 8601 timestamps. Return errors in one shape everywhere, for example `{ "error": { "code": "VALIDATION_FAILED", "message": "...", "details": [...] } }`, or the standard **Problem Details** format (RFC 9457).

### Beyond the basics

- **Statelessness**: each request carries everything needed (for example an auth token), which makes horizontal scaling easy.
- **HATEOAS**: responses include links to related actions. Rarely used in full, but useful to know.
- **JSON:API** is one opinionated convention for payload shape if your team wants a standard.

### Pitfalls

- Verbs in URLs (`/getUser`) and inconsistent naming across endpoints.
- Leaking database structure directly; your API is a contract, your schema is an implementation detail.

You are ready to move on when you can design the endpoints for a small e-commerce API on paper and defend every method and status code choice.

## Key concepts

- **Resources and URL design**
- **Methods and status codes in practice**
- **JSON conventions**
- **Error format and Problem Details**
- **Statelessness**
- **JSON:API specification**
- **HATEOAS**

## Mini project

Build a REST API for a recipe app with collections, nested ingredients, a custom action endpoint and one consistent error format across all failures.

## Check yourself

A client submits an order with an invalid quantity. Which status code do you return and what does the body look like?

## Free resources

- [MDN: HTTP request methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods) (MDN)
- [Fielding's dissertation: REST](https://ics.uci.edu/~fielding/pubs/dissertation/top.htm) (Roy Fielding)
- [JSON:API](https://jsonapi.org/) (jsonapi.org)

Previous: [When Databases Misbehave](https://www.internhack.in/roadmaps/tracks/backend/database-failure-modes) · Next: [Pagination, Versioning and Rate Limits](https://www.internhack.in/roadmaps/tracks/backend/api-evolution-and-limits)

## More in Designing and Documenting APIs

- [Resource-Oriented REST APIs](https://www.internhack.in/roadmaps/tracks/backend/rest-api-design)
- [Pagination, Versioning and Rate Limits](https://www.internhack.in/roadmaps/tracks/backend/api-evolution-and-limits)
- [API Contracts with OpenAPI](https://www.internhack.in/roadmaps/tracks/backend/openapi-docs)
- [GraphQL APIs](https://www.internhack.in/roadmaps/tracks/backend/graphql)
- [gRPC and Protocol Buffers](https://www.internhack.in/roadmaps/tracks/backend/grpc)
- [SOAP and Legacy Integrations](https://www.internhack.in/roadmaps/tracks/backend/soap-legacy-apis)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Backend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/backend)
