← All lessons
Backend fundamentals
Intermediate
15-30 min
HTTP, REST, and API Design Basics for Frontend Engineering Leaders
A practical guide to designing API contracts that are easier to debug, safer to evolve, and better for both users and teams.
Learn how HTTP, REST, and API design fit together so you can make better interface decisions, reduce integration surprises, and lead product conversations with more confidence.
Why this matters
What you gain from this lesson
Good APIs make frontend development faster because the UI can trust stable contracts.
Clear status codes and error shapes improve debugging, observability, and support.
A lead who understands API design can spot risks before the team ships them.
At a glance
Lesson map
Focus
Backend fundamentals
Outcome
Better decisions
This lesson is designed to stay readable on mobile: the basics are concise, the takeaways are highlighted, and the visual helps you see how the trade-offs fit together.
Core concepts
HTTP is the contract layer
HTTP is more than transport. The method, URL, headers, body, and status code all carry meaning that shapes product behavior.
- GET should read data, POST should create or trigger work, PATCH should partially update.
- Status codes communicate business outcome, not just technical success.
- Headers like Authorization, Cache-Control, and Idempotency-Key are part of the contract.
REST is about predictable resources
REST is useful because it pushes teams toward consistent resource naming and method usage without forcing academic purity.
- Use nouns for resources: /users/42, /orders/123, /cart/items/item_123.
- Keep requests stateless so each call carries enough context to stand alone.
- Prefer consistency and readability over clever endpoint shapes.
API design should match product workflows
A good API supports the user journey, not only the database schema. The frontend should not have to re-implement business rules.
- Return data in a shape that helps the screen render directly.
- Include capability or available action data when the UI needs it.
- Think about loading, empty, error, and partial states from the start.
Error, auth, and idempotency are reliability features
These details affect user trust and team velocity. If they are weak, retries, support, and debugging all get harder.
- 401 means authenticate again; 403 means authenticated but not allowed.
- Use stable error codes and request IDs so frontend and support can trace issues.
- For risky operations, idempotency keys prevent duplicate side effects when requests are retried.
Visual model
Practical examples
Login should not hide failure inside 200 OK
If the request failed, the HTTP response should say so. That keeps monitoring, retries, and client behavior honest.
Request or current behavior
POST /sessions
Content-Type: application/json
{
"email": "dome@example.com",
"password": "wrong-password"
}Better response
401 Unauthorized
{
"error": {
"code": "INVALID_CREDENTIALS",
"message": "Email or password is incorrect",
"requestId": "req_123"
}
}Lesson: Keep success and failure visible in the status code so the client and the server speak the same language.
Empty collections are usually not 404
If the collection exists but has no items, return an empty list rather than pretending the resource is missing.
Request or current behavior
GET /orders?userId=123Better response
200 OK
{
"items": [],
"nextCursor": null,
"hasMore": false
}Lesson: Use 404 for missing resources, not for valid but empty collections.
Payments need idempotency
Retries happen in real life. A payment endpoint should know whether a request is a duplicate.
Request or current behavior
POST /payments
Idempotency-Key: checkout_abc123
{
"orderId": "order_123",
"amount": 129.0
}Better response
201 Created
{
"paymentId": "pay_456",
"status": "SUCCEEDED"
}Lesson: When duplicate requests mean duplicate side effects, add an idempotency key.
Common pitfalls
Using POST for every action, which hides meaning and makes the API harder to reason about.
Returning 200 for every response, which weakens monitoring and client behavior.
Designing around database tables instead of product workflows and domain concepts.
Letting the frontend parse human-readable error strings instead of stable error codes.
Assuming the frontend can enforce security rules by hiding buttons or form controls.
Shipping breaking changes without a compatibility plan for older clients.
Quiz
Quiz 1
What is the difference between 401 and 403?
Think it through first, then reveal the answer.
Quiz 2
Why is returning 200 for every API response a bad idea?
Think it through first, then reveal the answer.
Quiz 3
Should GET /orders return 404 when the user has no orders?
Think it through first, then reveal the answer.
Quiz 4
Why does a payment API often need an idempotency key?
Think it through first, then reveal the answer.
Quiz 5
Is adding a new optional response field usually breaking?
Think it through first, then reveal the answer.
Takeaways
HTTP status codes are part of the product contract.
REST works best when APIs are predictable, resource-oriented, and consistent.
A strong API reduces frontend duplication and team friction.
Error handling, auth, and idempotency are reliability features, not extras.