course2_http_rest_api_design
Auto-Generated Notes
2025-08-21
Tag: course_note Title: HTTP and REST API Design Fundamentals
Overview These notes outline HTTP semantics and practical REST API
design: methods, status codes, resource modeling, and versioning. Includes
examples and best practices.
Learning Objectives - Use HTTP methods correctly (GET, POST, PUT, PATCH,
DELETE) - Choose appropriate status codes and headers - Model resources
and relationships with URLs - Version and document APIs; handle
pagination and filtering
1. HTTP Semantics Methods
GET (safe, idempotent): retrieve resources
POST (unsafe): create subordinate or trigger action
PUT (idempotent): replace resource
PATCH (idempotent by spec? not required): partial update
DELETE (idempotent): remove resource
Idempotency and safety guide retries and caching.
2. Status Codes 2xx: success (200 OK, 201 Created with Location, 204 No
Content) 4xx: client issues (400, 401, 403, 404, 409, 422, 429) 5xx: server
issues (500, 502, 503) with Retry-After when appropriate.
3. Resource Modeling Use nouns and hierarchy: /customers/{id}/orders.
Avoid verbs in paths; use methods for actions. Represent links for
discoverability.
4. Query Parameters Filtering ?status=active, sorting ?sort=-created_at,
pagination ?page=2&per_page=50. Return metadata (total, next, prev) in
response.
5. Headers and Caching ETag/If-None-Match for conditional requests;
Cache-Control and Expires for caching. Prefer 304 when content
unchanged.
6. Versioning Prefer URI (/v1/) or media type versioning. Deprecate
responsibly with clear timelines.
7. Errors Return machine-readable errors: { “code”: “validation_error”,
“message”: “…”, “field”: “email” }
8. Security TLS everywhere, OAuth2/OIDC for auth, rate limiting. Never
leak internal details in errors.
Exercises 1) Design endpoints for a library system: books, authors, loans. 2)
Define pagination and filtering for listing books. 3) Write example
requests/responses for creating a loan.
References - RFC 7231 (HTTP/1.1 Semantics), RFC 9110 updates - API Design
Guidelines by major platforms