Bird
0
0

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📝 Debug Q14 of 15
Rest API - Batch and Bulk Operations
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?
AAdd validation to return 400 Bad Request if array is empty
BChange HTTP method from POST to GET
CRemove JSON parsing from the endpoint
DAllow empty arrays and return 204 No Content
Step-by-Step Solution
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]
Quick Trick: Validate empty input to prevent server errors [OK]
Common Mistakes:
MISTAKES
  • Ignoring empty input causing crashes
  • Changing HTTP method incorrectly
  • Skipping JSON parsing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes