Complete the code to define the HTTP method for a batch create endpoint.
app.[1]('/items/batch', create_items_batch)
The batch create endpoint should use the POST method because it is used to create new resources.
Complete the code to accept a list of items in the request body for batch creation.
def create_items_batch(): items = request.[1]
request.json is used to get JSON data from the request body, which is typical for batch create endpoints.
Fix the error in the batch create function to correctly iterate over the items list.
def create_items_batch(): items = request.json for [1] in items: save_item(item) return {'status': 'success'}
The loop variable should be a single item, here named 'item', to iterate over the list 'items'.
Fill both blanks to validate each item has a 'name' key and return error if missing.
def create_items_batch(): items = request.json for item in items: if [1] not in item: return [2] return {'status': 'success'}
We check if 'name' key is missing in each item and return a specific error message if so.
Fill all three blanks to create a batch endpoint that saves items and returns count of created items.
def create_items_batch(): items = request.[1] count = 0 for [2] in items: save_item([3]) count += 1 return {'created': count}
The function reads JSON data, iterates over each item, saves it, and counts how many were created.