Client-Server, HTTP, and API Basics
Core Concepts (5)
- 1.Clients ask, servers answer, over a network
- 2.HTTP requests have a method, a path, headers, and a body
- 3.Stateless servers are easier to scale
- 4.An API is a contract that outlives its implementation
- 5.Status codes and errors are part of the design
Map to Your Experience
Open your browser developer tools on a site you use and look at one request. What did the client send and what came back?
Design Brief: Design a Small REST API
Learn
Most software you meet follows a client-server model. A client, such as a browser or phone app, sends a request. A server receives it, does some work, and sends a response. The client and server are separate programs, often on separate machines, joined by a network.
The web uses HTTP for this conversation. A request has a method describing intent, a path naming the resource, headers carrying metadata, and sometimes a body. GET reads, POST creates, PUT replaces, PATCH changes part, and DELETE removes. The response carries a status code and a body. Codes in the 200 range mean success, 400 range means the client made an error, and 500 range means the server failed.
An API, or application programming interface, is the agreed shape of those requests and responses. Treat it as a contract. Once other teams or customers depend on it, changing it breaks them, so API decisions fall squarely in the category of things that are expensive to change.
Good APIs are predictable. Paths name things, not actions: use /tasks and /tasks/42 rather than /createTask. Errors return a clear code and a helpful message. Lists are paginated so that no response grows without limit. Names and formats stay consistent across endpoints.
Statelessness matters for scaling. If each request carries everything the server needs, such as an authentication token, then any server can handle any request. Servers that remember a client between requests are harder to replace, restart, or multiply.
Finally, consider the network. Requests can be slow, lost, or duplicated. A client that retries a create request might create two tasks. Designing for that reality starts with understanding that a call across a network is not like a call inside one program.
Map
Pick three HTTP status codes and for each write a situation in a to-do app that would return it. Then decide which of these should be safe to retry without side effects: GET, POST, PUT, DELETE.
Design
Design a REST API for a to-do list service with endpoints to list, create, read, update, and delete tasks. For each, state method, path, success code, and at least one error code. Describe cursor or page based pagination for the list endpoint, and explain in two sentences how a version change would be introduced without breaking existing clients.
Requirements
- •Define 5 endpoints with methods and paths
- •List success and error status codes
- •Describe how list results are paginated
Constraints
- •Resource-oriented paths
- •Stateless server
Must Cover
Trade-off Axis
simplicity vs flexibility of the contract
Referenced Patterns
Competencies Advanced
Ready to Design?
Open this day in the Design Studio. The studio follows this track: its days, concepts, patterns and trade-offs are loaded, and you keep one design across the whole track.
Open in Studio →