Restful API design Flashcards
What
Identify the Goal: What problem does the API solve? What resources will it manage?
Set Functionalities: List actions the API will support, like creating, reading, updating, or deleting resources.
Identify Resources
Resources represent the main entities in your API and are typically nouns.
Users
Orders
Products
Use Resource URIs
Design resource URLs that are hierarchical, predictable, and meaningful.
Use nouns to represent resources.
Use plural for resource names (e.g., /users instead of /user).
/users – Get all users or create a new user.
/users/{id} – Access a specific user by ID.
/users/{id}/orders – Access orders for a specific user.
Map to HTTP Methods
GET: Retrieve resources.
POST: Create new resources.
PUT: Update an existing resource (replace the whole).
PATCH: Partially update a resource.
DELETE: Remove a resource.
GET /users – Fetch all users.
POST /users – Create a new user.
PUT /users/{id} – Update user details.
DELETE /users/{id} – Delete a user.
Versioning Handling
API versions ensure backward compatibility when introducing changes
GET /v1/users
Error Codes
200 OK: Successful GET or PUT request.
201 Created: Resource successfully created.
204 No Content: Successful DELETE request.
400 Bad Request: Invalid input.
401 Unauthorized: Authentication failure.
404 Not Found: Resource not found.
500 Internal Server Error: Server failure.