Quiz Entry - updated: 2026.07.05
What is the basic syntax of the fetch() function?
Calling fetch(url, options) returns a Promise that resolves to a Response object once the headers arrive.
const response = await fetch('/api/users', {
method: 'GET',
headers: { 'Accept': 'application/json' }
});
The options parameter is optional for simple GET requests. The Promise resolves even for HTTP error status codes (404, 500) - you must check response.ok.
Go deeper:
MDN: Window.fetch() — the reference for the signature, return value, and why it only rejects on network errors.
MDN: Using the Fetch API — guide covering requests, headers, credentials, cancellation, and reading responses.