Bird
Raised Fist0
Rest APIprogramming~20 mins

Batch create endpoint design in Rest API - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Batch Create Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:00remaining
Best HTTP method for batch create

Which HTTP method is most appropriate for a batch create endpoint in a REST API?

AGET
BPUT
CPOST
DDELETE
Attempts:
2 left
💡 Hint

Think about which method is used to create new resources.

❓ Predict Output
intermediate
1:00remaining
Response status code for successful batch create

What is the correct HTTP status code returned after successfully creating multiple resources in a batch?

A201 Created
B200 OK
C204 No Content
D400 Bad Request
Attempts:
2 left
💡 Hint

Consider the status code that indicates resource creation.

❓ Predict Output
advanced
1:30remaining
Batch create response body format

Given a batch create request that creates three new users, which response body best follows REST API best practices?

Rest API
Request body:
[
  {"name": "Alice"},
  {"name": "Bob"},
  {"name": "Charlie"}
]
A{"message": "Users created successfully"}
B{"created": 3}
C["/users/1", "/users/2", "/users/3"]
D[{"id": 1, "name": "Alice"}, {"id": 2, "name": "Bob"}, {"id": 3, "name": "Charlie"}]
Attempts:
2 left
💡 Hint

Think about returning the created resources with their new IDs.

🧠 Conceptual
advanced
2:00remaining
Handling partial failures in batch create

In a batch create endpoint, if some items fail validation but others succeed, what is the best practice for the response?

AReturn 400 Bad Request with details about all failed items and no created items
BReturn 207 Multi-Status with details about success and failure for each item
CReturn 201 Created with only the successfully created items in the response body
DReturn 500 Internal Server Error because partial success is not allowed
Attempts:
2 left
💡 Hint

Think about how to communicate mixed results clearly.

🚀 Application
expert
2:30remaining
Designing idempotent batch create endpoint

You want to design a batch create endpoint that is idempotent (safe to retry without creating duplicates). Which approach is best?

ARequire clients to send a unique client-generated ID for each item and reject duplicates
BAllow duplicates and rely on server to filter them after creation
CUse POST without any client IDs and accept duplicates on retries
DUse GET method to create resources so retries do not duplicate
Attempts:
2 left
💡 Hint

Think about how to identify repeated requests uniquely.

Practice

(1/5)
1. What HTTP method is typically used for a batch create endpoint in a REST API?
easy
A. DELETE
B. POST
C. GET
D. PUT

Solution

  1. Step 1: Understand HTTP methods for data creation

    POST is used to create new resources on the server.
  2. Step 2: Apply to batch create context

    Batch create sends multiple new items in one POST request.
  3. Final Answer:

    POST -> Option B
  4. Quick Check:

    Batch create uses POST [OK]
Hint: Batch create always uses POST method [OK]
Common Mistakes:
  • Using GET which is for reading data
  • Using DELETE which removes data
  • Using PUT which replaces resources
2. Which of the following is the correct JSON format for sending multiple items in a batch create request body?
easy
A. {"name": "item1", "name": "item2"}
B. [{"name": "item1"}, {"name": "item2"}]
C. {"items": [{"name": "item1"}, {"name": "item2"}]}
D. {"item1": "name", "item2": "name"}

Solution

  1. Step 1: Identify JSON array structure for batch data

    Batch create expects an object with a key containing an array of items.
  2. Step 2: Match correct JSON format

    {"items": [{"name": "item1"}, {"name": "item2"}]} is a JSON object with an array of objects, which is correct for batch create.
  3. Final Answer:

    {"items": [{"name": "item1"}, {"name": "item2"}]} -> Option C
  4. Quick Check:

    Batch create body = JSON object with items array [OK]
Hint: Batch create body is a JSON object with an array of items [OK]
Common Mistakes:
  • Using duplicate keys in one object
  • Sending a single object instead of an array
  • Using incorrect JSON syntax
3. Given this batch create endpoint code snippet, what will be the response if one item is invalid?
POST /items/batch
Request body: [{"name": "item1"}, {"name": ""}]

Response: 400 Bad Request
{
  "error": "Validation failed",
  "details": [{"index": 1, "message": "Name cannot be empty"}]
}
medium
A. Server crashes due to invalid input
B. All items are created, ignoring the invalid one
C. Only the valid items are created, error ignored
D. No items are created, and error details are returned

Solution

  1. Step 1: Understand validation behavior in batch create

    If any item is invalid, the server should reject the whole batch to keep data consistent.
  2. Step 2: Analyze the response code and message

    Response 400 with error details means no items were created and client is informed.
  3. Final Answer:

    No items are created, and error details are returned -> Option D
  4. Quick Check:

    Validation failure returns 400 with errors [OK]
Hint: Validation errors cause full batch rejection [OK]
Common Mistakes:
  • Assuming partial success without error
  • Ignoring error details in response
  • Expecting server to crash on bad input
4. You wrote a batch create endpoint but clients report that sending an empty array causes a 500 Internal Server Error. What is the likely fix?
medium
A. Add validation to return 400 Bad Request if array is empty
B. Change HTTP method from POST to GET
C. Remove JSON parsing from the endpoint
D. Allow empty arrays and return 204 No Content

Solution

  1. Step 1: Identify cause of 500 error on empty input

    Server likely crashes because it does not handle empty arrays properly.
  2. Step 2: Implement input validation for empty arrays

    Return 400 Bad Request to inform client that empty batch is invalid.
  3. Final Answer:

    Add validation to return 400 Bad Request if array is empty -> Option A
  4. Quick Check:

    Validate input to avoid server errors [OK]
Hint: Validate empty input to prevent server errors [OK]
Common Mistakes:
  • Ignoring empty input causing crashes
  • Changing HTTP method incorrectly
  • Skipping JSON parsing
5. You want to design a batch create endpoint that returns the ID of each created item and reports errors per item without failing the whole batch. Which response design is best?
hard
A. {"results": [{"id": 1, "status": "created"}, {"error": "Invalid name", "status": "failed"}]}
B. {"error": "Batch failed", "status": 400}
C. [{"id": 1}, {"id": 2}]
D. {"message": "All items created successfully"}

Solution

  1. Step 1: Understand partial success reporting

    To report success or failure per item, response must include status and details for each.
  2. Step 2: Match response format to requirements

    {"results": [{"id": 1, "status": "created"}, {"error": "Invalid name", "status": "failed"}]} provides per-item status and error messages, allowing partial success.
  3. Final Answer:

    {"results": [{"id": 1, "status": "created"}, {"error": "Invalid name", "status": "failed"}]} -> Option A
  4. Quick Check:

    Per-item status in response enables partial success [OK]
Hint: Return per-item status and errors in response [OK]
Common Mistakes:
  • Failing whole batch on one error
  • Returning only success without error info
  • Using generic messages without details
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