Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to send a batch request using the fetch API.
Rest API
fetch('/api/batch', { method: '[1]' })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST for batch requests.
✗ Incorrect
Batch operations usually use POST to send multiple requests in one call.
2fill in blank
mediumComplete the code to create a batch payload with multiple requests.
Rest API
const batchPayload = { requests: [[1]] }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to wrap the request in an object or array.
✗ Incorrect
The requests array contains objects describing each request.
3fill in blank
hardFix the error in the code to send batch requests correctly.
Rest API
fetch('/api/batch', { method: 'POST', body: JSON.stringify([1]) })
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong case for variable names.
✗ Incorrect
The variable name is case sensitive and must be exactly 'batchPayload'.
4fill in blank
hardFill both blanks to handle the batch response and extract results.
Rest API
fetch('/api/batch', { method: 'POST', body: JSON.stringify(batchPayload) }) .then(response => response.[1]()) .then(data => data.[2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using response.text() instead of response.json().
Accessing wrong property name.
✗ Incorrect
Use response.json() to parse JSON, then access the 'results' array from the data.
5fill in blank
hardFill all three blanks to create a batch request, send it, and log each response status.
Rest API
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));
}); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing HTTP methods incorrectly.
Not parsing response as JSON.
✗ Incorrect
The first request uses GET, the second POST, and the response is parsed as JSON.