Complete the code to send a batch request using the fetch API.
fetch('/api/batch', { method: '[1]' })
Batch operations usually use POST to send multiple requests in one call.
Complete the code to create a batch payload with multiple requests.
const batchPayload = { requests: [[1]] };The requests array contains objects describing each request.
Fix the error in the code to send batch requests correctly.
fetch('/api/batch', { method: 'POST', body: JSON.stringify([1]) })
The variable name is case sensitive and must be exactly 'batchPayload'.
Fill both blanks to handle the batch response and extract results.
fetch('/api/batch', { method: 'POST', body: JSON.stringify(batchPayload) }) .then(response => response.[1]()) .then(data => data.[2]);
Use response.json() to parse JSON, then access the 'results' array from the data.
Fill all three blanks to create a batch request, send it, and log each response status.
const batchPayload = { requests: [
{ method: '[1]', path: '/users' },
{ method: '[2]', path: '/posts' }
] };
fetch('/api/batch', { method: 'POST', body: JSON.stringify(batchPayload) })
.then(res => res.[3]())
.then(data => {
data.results.forEach(r => console.log(r.status));
});The first request uses GET, the second POST, and the response is parsed as JSON.
