Bird
Raised Fist0
Rest APIprogramming~20 mins

Batch update patterns in Rest API - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Batch Update Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this batch update response?

Consider a REST API that accepts a batch update request for multiple user records. The server responds with a JSON object summarizing the update results.

{
  "results": [
    {"id": 1, "status": "updated"},
    {"id": 2, "status": "not_found"},
    {"id": 3, "status": "updated"}
  ],
  "summary": {
    "updated": 2,
    "not_found": 1
  }
}

What is the value of response.summary.updated?

A0
B3
C1
D2
Attempts:
2 left
💡 Hint

Count how many items have status "updated" in the results array.

🧠 Conceptual
intermediate
1:30remaining
Which HTTP method is most appropriate for batch updates?

You want to update multiple resources in a single REST API call. Which HTTP method should you use according to REST principles?

APOST
BPUT
CGET
DDELETE
Attempts:
2 left
💡 Hint

Think about which method is used to replace or update resources.

🔧 Debug
advanced
2:00remaining
Why does this batch update API return a 400 error?

Given this batch update request payload:

{
  "updates": [
    {"id": 1, "name": "Alice"},
    {"name": "Bob"}
  ]
}

The server responds with HTTP 400 Bad Request. What is the most likely cause?

AServer timeout
BInvalid HTTP method used
CMissing 'id' field in one update object
DEmpty updates array
Attempts:
2 left
💡 Hint

Check if all update objects have required fields.

📝 Syntax
advanced
1:30remaining
Which JSON payload is valid for a batch update?

Choose the valid JSON payload for updating multiple items in one request.

A{ "updates": [{ "id": 1, "value": "x" }, { "id": 2, "value": "y" }] }
B{ "updates": { "id": 1, "value": "x" }, { "id": 2, "value": "y" } }
C[ { "id": 1, "value": "x" }, { "id": 2, "value": "y" } ]
D{ "updates": [ { "id": 1, "value": "x" }, { "id": 2, "value": "y" } ] }
Attempts:
2 left
💡 Hint

Check for proper JSON object and array syntax.

🚀 Application
expert
2:30remaining
How many items are updated after this batch request?

A batch update request sends the following payload:

{
  "updates": [
    {"id": 1, "status": "active"},
    {"id": 2, "status": "inactive"},
    {"id": 3, "status": "active"},
    {"id": 4, "status": "active"}
  ]
}

The server processes the batch and returns this response:

{
  "results": [
    {"id": 1, "status": "updated"},
    {"id": 2, "status": "error", "message": "Invalid status"},
    {"id": 3, "status": "updated"},
    {"id": 4, "status": "updated"}
  ]
}

How many items were successfully updated?

A3
B4
C2
D1
Attempts:
2 left
💡 Hint

Count how many results have status "updated".

Practice

(1/5)
1. What is the main advantage of using batch update patterns in REST APIs?
easy
A. They only work with GET requests.
B. They allow updating multiple items with a single request, saving time.
C. They require sending separate requests for each item.
D. They increase the number of requests to the server.

Solution

  1. Step 1: Understand batch update purpose

    Batch update patterns let you update many items at once instead of one by one.
  2. Step 2: Identify the benefit

    This reduces the number of requests and saves time and server resources.
  3. Final Answer:

    They allow updating multiple items with a single request, saving time. -> Option B
  4. Quick Check:

    Batch update = single request for many items [OK]
Hint: Batch updates reduce requests by combining many updates [OK]
Common Mistakes:
  • Thinking batch updates increase requests
  • Confusing batch update with single item update
  • Assuming batch updates use GET method
2. Which HTTP method is most appropriate for batch updates in REST APIs?
easy
A. GET
B. POST
C. PATCH
D. DELETE

Solution

  1. Step 1: Recall HTTP methods for updates

    PATCH is used to partially update resources, suitable for batch updates.
  2. Step 2: Eliminate other methods

    GET retrieves data, POST creates new data, DELETE removes data, so they are not best for batch updates.
  3. Final Answer:

    PATCH -> Option C
  4. Quick Check:

    Batch update uses PATCH method [OK]
Hint: Use PATCH for partial or batch updates [OK]
Common Mistakes:
  • Using GET for updates
  • Confusing POST with update method
  • Using DELETE instead of PATCH
3. Given this JSON payload sent in a PATCH request for batch update:
[{"id":1,"status":"done"},{"id":2,"status":"pending"}]

What does this payload represent?
medium
A. Retrieve items with id 1 and 2.
B. Create two new items with given ids and statuses.
C. Delete items with id 1 and 2.
D. Update status of items with id 1 and 2 to 'done' and 'pending' respectively.

Solution

  1. Step 1: Analyze JSON payload

    The payload is an array of objects each with 'id' and 'status' fields, indicating updates.
  2. Step 2: Understand PATCH semantics

    PATCH updates existing items partially, so this changes status fields for items with id 1 and 2.
  3. Final Answer:

    Update status of items with id 1 and 2 to 'done' and 'pending' respectively. -> Option D
  4. Quick Check:

    PATCH with array updates multiple items [OK]
Hint: PATCH with array updates multiple items by id [OK]
Common Mistakes:
  • Thinking PATCH creates new items
  • Confusing update with delete
  • Assuming it retrieves data
4. You send this PATCH request payload to update multiple items:
[{"id":1,"status":"done"}, {"status":"pending"}]

What is the likely problem?
medium
A. Missing 'id' in second object causes update failure or error.
B. The payload is valid and will update all items.
C. Using PATCH instead of POST causes syntax error.
D. The array should be empty for batch updates.

Solution

  1. Step 1: Check each object in payload

    The second object lacks 'id', so the server cannot identify which item to update.
  2. Step 2: Understand update requirements

    Each update must specify the item to update, usually by 'id'. Missing it causes failure or error.
  3. Final Answer:

    Missing 'id' in second object causes update failure or error. -> Option A
  4. Quick Check:

    Each update needs an identifier like 'id' [OK]
Hint: Every update object must include an identifier like 'id' [OK]
Common Mistakes:
  • Assuming missing 'id' is allowed
  • Confusing PATCH with POST errors
  • Thinking empty arrays are required
5. You want to batch update user roles but only for users currently active. Which pattern best fits this requirement?
hard
A. Send a PATCH request with an array of user objects filtered to active users only.
B. Send separate PATCH requests for all users regardless of status.
C. Use GET request to update roles for active users.
D. Send a DELETE request with active users to update roles.

Solution

  1. Step 1: Identify filtering need

    Only active users should be updated, so filter users before sending batch update.
  2. Step 2: Choose correct method and payload

    PATCH with an array of filtered user objects updates roles efficiently in one request.
  3. Final Answer:

    Send a PATCH request with an array of user objects filtered to active users only. -> Option A
  4. Quick Check:

    Filter then batch update with PATCH [OK]
Hint: Filter data first, then batch update with PATCH [OK]
Common Mistakes:
  • Sending updates for all users without filtering
  • Using GET or DELETE for updates
  • Sending multiple separate requests instead of batch
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard