llmstory
RESTful API Principles and Refactoring Challenge
1.

Define REST as an architectural style.

2.

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.

3.

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.

4.

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).

5.

Briefly explain the different categories of HTTP status codes (1xx, 2xx, 3xx, 4xx, 5xx).

6.

For the following scenario, identify the most appropriate HTTP status code(s): Successful retrieval of a resource.

7.

For the following scenario, identify the most appropriate HTTP status code(s): Successful creation of a new resource.

8.

For the following scenario, identify the most appropriate HTTP status code(s): Successful update (full replacement) of a resource.

9.

For the following scenario, identify the most appropriate HTTP status code(s): Successful partial update of a resource.

10.

For the following scenario, identify the most appropriate HTTP status code(s): Successful deletion of a resource (with no content to return).

11.

For the following scenario, identify the most appropriate HTTP status code(s): Request missing required parameters or having invalid data.

12.

For the following scenario, identify the most appropriate HTTP status code(s): Client is not authenticated.

13.

For the following scenario, identify the most appropriate HTTP status code(s): Client is authenticated but lacks necessary permissions.

14.

For the following scenario, identify the most appropriate HTTP status code(s): Resource not found.

15.

For the following scenario, identify the most appropriate HTTP status code(s): Conflict due to current state of a resource (e.g., optimistic locking).

16.

For the following scenario, identify the most appropriate HTTP status code(s): An unexpected error occurred on the server.

17.

Scenario 1: Request to create a new post. Flawed Design: POST /posts/createPost

  1. Identify Violations: State which REST principle(s) are violated.
  2. Explain Why: Briefly explain why the current design is problematic.
  3. Propose Refactoring: Provide the corrected HTTP Method and URL path, adhering to RESTful principles.
  4. Suggest Status Codes: Suggest appropriate HTTP status codes for a successful response and one common failure scenario for your refactored endpoint.
18.

Scenario 2: Request to delete a specific post. Flawed Design: GET /posts/deletePost?id=123

  1. Identify Violations: State which REST principle(s) are violated.
  2. Explain Why: Briefly explain why the current design is problematic.
  3. Propose Refactoring: Provide the corrected HTTP Method and URL path, adhering to RESTful principles.
  4. Suggest Status Codes: Suggest appropriate HTTP status codes for a successful response and one common failure scenario for your refactored endpoint.
19.

Scenario 3: Request to update a user's profile information (full replacement). Flawed Design: POST /users/updateUser/456 (with user data in request body)

  1. Identify Violations: State which REST principle(s) are violated.
  2. Explain Why: Briefly explain why the current design is problematic.
  3. Propose Refactoring: Provide the corrected HTTP Method and URL path, adhering to RESTful principles.
  4. Suggest Status Codes: Suggest appropriate HTTP status codes for a successful response and one common failure scenario for your refactored endpoint.
20.

Scenario 4: Request to retrieve a list of all products. Flawed Design: GET /products/getAllProducts

  1. Identify Violations: State which REST principle(s) are violated.
  2. Explain Why: Briefly explain why the current design is problematic.
  3. Propose Refactoring: Provide the corrected HTTP Method and URL path, adhering to RESTful principles.
  4. Suggest Status Codes: Suggest appropriate HTTP status codes for a successful response and one common failure scenario for your refactored endpoint.
21.

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)

  1. Identify Violations: State which REST principle(s) are violated.
  2. Explain Why: Briefly explain why the current design is problematic.
  3. Propose Refactoring: Provide the corrected HTTP Method and URL path, adhering to RESTful principles.
  4. Suggest Status Codes: Suggest appropriate HTTP status codes for a successful response and one common failure scenario for your refactored endpoint.
Copyright © 2025 llmstory.comPrivacy PolicyTerms of Service