Learn how to build, test, deploy, and maintain robust software systems.
An API (Application Programming Interface) is a contract that lets one piece of software talk to another. A RESTful API is an API designed around a set of architectural principles: resources identified by URLs, a small set of HTTP methods, and stateless communication. This lesson teaches how to design an API that is predictable, well-documented, and safe: resources and methods, status codes, validation, pagination, authentication and authorization, and API documentation with OpenAPI. Good API design is what makes an API pleasant to use for years. Bad API design is what makes clients hate you.
The API is the interface: the documented ways a client can interact with a system.
REST (Representational State Transfer) is an architectural style, not a single tool. Its core idea is that clients interact with resources through a small, uniform set of operations. It is more than "GET reads and POST creates."
Design around resources (nouns), not actions. A resource is a thing: a user, a post, an order.
| Method | Purpose | Idempotent? |
|---|---|---|
| GET | Read a resource | Yes |
| POST | Create a resource | No |
| PUT | Replace a resource | Yes |
| PATCH | Partially update a resource | No |
| DELETE | Remove a resource | Yes |
| Code | Meaning |
|---|---|
| 200 | OK |
| 201 | Created |
| 204 | No content |
| 400 | Bad request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not found |
| 409 | Conflict |
| 422 | Unprocessable entity |
| 429 | Too many requests |
| 500 | Internal server error |
| 503 | Service unavailable |
Use the right code. 401 means "not authenticated"; 403 means "authenticated but not allowed"; 404 means "does not exist."
Never trust client input. Validate required fields, types, lengths, and allowed values. Return a consistent error structure so clients can react predictably.
Never return thousands of records at once. Paginate with an offset or a cursor.
| Offset pagination | Cursor pagination | |
|---|---|---|
| How | page and limit | A cursor pointing at the next item |
| Pros | Simple | Stable under inserts/deletes |
| Cons | Drifts when data changes | Slightly more complex |
A JWT (JSON Web Token) is a signed token issued at login and sent with each request to prove identity. OAuth is a standard for delegated authorization — letting an app act on a user’s behalf without knowing their password.
OpenAPI describes an API in a machine-readable way, so tools can generate documentation, client code, and tests from a single source of truth.
Note the correct status codes: 201 for created, 404 for missing, 400 for invalid input.
A client creates a post and the server returns 201.
201 Created
{ "id": 1, "title": "Hello" }Requesting a missing resource returns 404.
404 Not Found