Bird
0
0

You want to design an API to manage orders and their items. Which URL and HTTP method combination best follows resource-based design to update the quantity of item 7 in order 42?

hard📝 Application Q15 of 15
Rest API - REST API Fundamentals
You want to design an API to manage orders and their items. Which URL and HTTP method combination best follows resource-based design to update the quantity of item 7 in order 42?
APOST /orders/42/items with item ID and quantity in body
BPUT /orders/42/items/7 with updated quantity in body
CDELETE /orders/42/items/7 to update quantity
DGET /orders/42/items/7 with quantity in query
Step-by-Step Solution
Solution:
  1. Step 1: Identify the resource and action

    The resource is the specific item (ID 7) inside order 42. Updating quantity means modifying this resource.
  2. Step 2: Choose correct HTTP method and URL

    PUT is used to update existing resources. The URL should point to the specific item resource: /orders/42/items/7.
  3. Final Answer:

    PUT /orders/42/items/7 with updated quantity in body -> Option B
  4. Quick Check:

    Update nested resource = PUT to specific item URL [OK]
Quick Trick: Use PUT on specific nested resource URL to update it [OK]
Common Mistakes:
  • Using POST to update existing item
  • Using DELETE to update data
  • Using GET with query to change data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes