π Protocol Guide
RESTful API
RESTful API refers to interfaces built around the REST style put forward by Roy Fielding. Its heart is resource orientation: each piece of data is a resource reached through a URI, and each HTTP method communicates a clear intent. That straightforward model is why REST dominates modern web integration.
REST Design Tenets
- Statelessness: Every request carries its own full context; no sessions are kept server-side.
- Decoupled roles: Client presentation and server logic stay independent.
- Standard actions: GET, POST, PUT, DELETE express all CRUD behavior.
- Cacheability: Content marked cacheable improves responsiveness.
- Layered systems: Scalability improves when intermediaries are allowed.
HTTP Verbs
- GET: Fetch a resource; harmless and repeatable.
- POST: Create a resource or trigger a data-driven action.
- PUT: Replace a resource entirely.
- DELETE: Remove a resource.
- PATCH: Make a targeted partial update.
URL Design
Keep verbs out of URLs β methods carry that meaning. Resources use nouns, and IDs locate single items inside collections. A books example:
GET /books: Fetch all books.GET /books/{id}: Fetch one book.POST /books: Create a book.PUT /books/{id}: Update one book fully.DELETE /books/{id}: Delete one book.
Response Status Codes
REST APIs signal results using standard status codes:
- 200 OK: Request processed and data returned.
- 201 Created: New resource made.
- 204 No Content: Processed without a body.
- 400 Bad Request: Input could not be processed.
- 401 Unauthorized: Access not permitted.
- 404 Not Found: Resource missing.
- 500 Internal Server Error: Server-side failure.
Summary
Simple rules, universal standards, and familiar HTTP semantics make RESTful APIs easy to adopt and hard to outgrow, fitting projects from minimal prototypes to enterprise architectures.
