0
0
Rest APIprogramming~10 mins

Why batch operations reduce round trips in Rest API - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
APOST
BGET
CPUT
DDELETE
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST for batch requests.
2fill in blank
medium

Complete 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'
A[{ method: 'GET', path: '/users' }]
Bmethod: 'GET', path: '/users'
C{ method: 'GET', path: '/users' }
D'{ method: GET, path: /users }'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to wrap the request in an object or array.
3fill in blank
hard

Fix 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'
AbatchPayload
Bbatchpayload
CbatchPayload.toString()
DbatchPayload.json()
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong case for variable names.
4fill in blank
hard

Fill 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'
Ajson
Bresults
Ctext
Dbody
Attempts:
3 left
💡 Hint
Common Mistakes
Using response.text() instead of response.json().
Accessing wrong property name.
5fill in blank
hard

Fill 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'
AGET
BPOST
Cjson
DPUT
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing HTTP methods incorrectly.
Not parsing response as JSON.