Define REST as an architectural style.
Explain the six architectural constraints of REST (Client-Server, Stateless, Cacheable, Uniform Interface, Layered System, Code-On-Demand). Elaborate briefly on what each constraint means and why it's important for RESTful design. Mention that Code-On-Demand is optional.
Explain the proper use cases for the following HTTP verbs in a RESTful context: GET, POST, PUT, PATCH, and DELETE. For each verb, discuss its idempotency and safety characteristics.
Explain the concept of resource-based URLs. Contrast this with verb-based URLs, providing clear examples of both good (resource-based) and bad (verb-based) practices for common operations (e.g., fetching a list, retrieving a single item, creating, updating, deleting).
Briefly explain the different categories of HTTP status codes (1xx, 2xx, 3xx, 4xx, 5xx).
For the following scenario, identify the most appropriate HTTP status code(s): Successful retrieval of a resource.
For the following scenario, identify the most appropriate HTTP status code(s): Successful creation of a new resource.
For the following scenario, identify the most appropriate HTTP status code(s): Successful update (full replacement) of a resource.
For the following scenario, identify the most appropriate HTTP status code(s): Successful partial update of a resource.
For the following scenario, identify the most appropriate HTTP status code(s): Successful deletion of a resource (with no content to return).
For the following scenario, identify the most appropriate HTTP status code(s): Request missing required parameters or having invalid data.
For the following scenario, identify the most appropriate HTTP status code(s): Client is not authenticated.
For the following scenario, identify the most appropriate HTTP status code(s): Client is authenticated but lacks necessary permissions.
For the following scenario, identify the most appropriate HTTP status code(s): Resource not found.
For the following scenario, identify the most appropriate HTTP status code(s): Conflict due to current state of a resource (e.g., optimistic locking).
For the following scenario, identify the most appropriate HTTP status code(s): An unexpected error occurred on the server.
Scenario 1: Request to create a new post.
Flawed Design: POST /posts/createPost
- Identify Violations: State which REST principle(s) are violated.
- Explain Why: Briefly explain why the current design is problematic.
- Propose Refactoring: Provide the corrected HTTP Method and URL path, adhering to RESTful principles.
- Suggest Status Codes: Suggest appropriate HTTP status codes for a successful response and one common failure scenario for your refactored endpoint.
Scenario 2: Request to delete a specific post.
Flawed Design: GET /posts/deletePost?id=123
- Identify Violations: State which REST principle(s) are violated.
- Explain Why: Briefly explain why the current design is problematic.
- Propose Refactoring: Provide the corrected HTTP Method and URL path, adhering to RESTful principles.
- Suggest Status Codes: Suggest appropriate HTTP status codes for a successful response and one common failure scenario for your refactored endpoint.
Scenario 3: Request to update a user's profile information (full replacement).
Flawed Design: POST /users/updateUser/456
(with user data in request body)
- Identify Violations: State which REST principle(s) are violated.
- Explain Why: Briefly explain why the current design is problematic.
- Propose Refactoring: Provide the corrected HTTP Method and URL path, adhering to RESTful principles.
- Suggest Status Codes: Suggest appropriate HTTP status codes for a successful response and one common failure scenario for your refactored endpoint.
Scenario 4: Request to retrieve a list of all products.
Flawed Design: GET /products/getAllProducts
- Identify Violations: State which REST principle(s) are violated.
- Explain Why: Briefly explain why the current design is problematic.
- Propose Refactoring: Provide the corrected HTTP Method and URL path, adhering to RESTful principles.
- Suggest Status Codes: Suggest appropriate HTTP status codes for a successful response and one common failure scenario for your refactored endpoint.
Scenario 5: Request to change the status of an order (e.g., from 'pending' to 'shipped').
Flawed Design: PUT /orders/changeOrderStatus/789
(with new status in request body)
- Identify Violations: State which REST principle(s) are violated.
- Explain Why: Briefly explain why the current design is problematic.
- Propose Refactoring: Provide the corrected HTTP Method and URL path, adhering to RESTful principles.
- Suggest Status Codes: Suggest appropriate HTTP status codes for a successful response and one common failure scenario for your refactored endpoint.