Encyclopedia / JavaScript
fetch()
How browser JavaScript makes HTTP requests.
This is where the frontend meets the backend. fetch() calls an API, waits for the response and updates the DOM with the result. The browser's same-origin policy and CORS headers decide which other sites a page may call.
const r = await fetch('/api/contact', {
method: 'POST',
body: JSON.stringify({ email, message })
});
Related terms
Where it shows up in a page load
- Step 10: JavaScript makes it interactive. Scripts run, attach event listeners and may fetch more data from an API. How quickly the page responds to a tap is INP, another Core Web Vital.
Watch the full request journey →
More in JavaScript
What happens when someone clicks, types or scrolls.