fetch

fetch is JavaScript's native function for sending HTTP requests. It takes a URL and options (method, headers, body) and returns a promise that resolves with a Response object. It only rejects on a network error: a 404 or 500 status does not cause a rejection.

Example

const r = await fetch('/api/items', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ nom: 'x' })
})

Related concepts

The whole glossary