Complete the code to make a GET request to read data from the server.
fetch('[1]') .then(response => response.json()) .then(data => console.log(data));
The GET request URL should be the endpoint string only, like '/api/data'.
Complete the code to specify the GET method explicitly in the fetch options.
fetch('/api/items', { method: '[1]' }) .then(response => response.json()) .then(data => console.log(data));
To read data, the HTTP method should be 'GET'.
Fix the error in the fetch call to correctly read JSON data from the response.
fetch('/api/users') .then(response => response.[1]()) .then(data => console.log(data));
Use response.json() to parse the response body as JSON.
Fill both blanks to create a GET request with headers to accept JSON.
fetch('/api/products', { method: '[1]', headers: { 'Accept': '[2]' } }) .then(response => response.json()) .then(data => console.log(data));
The method should be 'GET' and the Accept header should be 'application/json' to request JSON data.
Fill all three blanks to fetch a resource by ID and handle errors properly.
fetch(`/api/items/[1]`) .then(response => { if (!response.[2]) throw new Error('Network error'); return response.json(); }) .then(data => console.log(data)) .catch(error => console.error('[3]', error));
Use the resource ID '42' in the URL, check response.ok for success, and log 'Fetch failed' on error.
