Complete the code to specify the HTTP method for batch updating resources.
fetch('/api/items/batch', { method: '[1]', body: JSON.stringify(data) })
The PUT method is commonly used for batch updates because it replaces the entire resource or collection.
Complete the code to set the correct Content-Type header for sending JSON data in a batch update request.
fetch('/api/items/batch', { method: 'PUT', headers: { 'Content-Type': '[1]' }, body: JSON.stringify(data) })
The application/json Content-Type header tells the server that the request body contains JSON data.
Fix the error in the batch update request by choosing the correct URL path segment for batch operations.
fetch('/api/items/[1]', { method: 'PUT', body: JSON.stringify(data) })
The path segment batch clearly indicates a batch operation, which is a common REST API pattern.
Fill both blanks to create a batch update request that sends an array of items and expects a JSON response.
fetch('/api/items/batch', { method: '[1]', headers: { 'Content-Type': '[2]' }, body: JSON.stringify(items) })
Use PUT for batch updating and application/json as the Content-Type for JSON data.
Fill all three blanks to handle a batch update with error checking and JSON response parsing.
async function batchUpdate(items) {
const response = await fetch('/api/items/batch', {
method: '[1]',
headers: { 'Content-Type': '[2]' },
body: JSON.stringify(items)
});
if (!response.ok) throw new Error('Batch update failed');
const result = await response.[3]();
return result;
}Use PUT for the method, application/json for the Content-Type, and json() to parse the JSON response.