Complete the code to specify the HTTP method for batch delete.
fetch('/items', { method: '[1]' })
The HTTP method DELETE is used to remove resources, including batch deletes.
Complete the code to send a JSON array of IDs to delete in the request body.
fetch('/items/batch-delete', { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ [1]: [1, 2, 3] }) })
The key ids clearly indicates the list of item IDs to delete.
Fix the error in the fetch call to correctly send a batch delete request with JSON body.
fetch('/items/delete', { method: 'DELETE', body: [1] })
The body must be a JSON string, so JSON.stringify is needed.
Fill both blanks to create a batch delete function that sends IDs in JSON body and sets headers.
function batchDelete(ids) {
return fetch('/items/batch', {
method: '[1]',
headers: { '[2]': 'application/json' },
body: JSON.stringify({ ids })
});
}The method must be DELETE and the header key for JSON is Content-Type.
Fill all three blanks to implement a batch delete with error handling and JSON response parsing.
async function batchDelete(ids) {
const response = await fetch('/items/batch-delete', {
method: '[1]',
headers: { '[2]': 'application/json' },
body: JSON.stringify({ ids })
});
if (!response.[3]) throw new Error('Delete failed');
return response.json();
}The method is DELETE, header key is Content-Type, and response.ok checks success.