fetch()
native browser feature that provides promise based HTTP requests [converted by browser]
method
: 'GET'
, 'POST'
, etc.mode
: CORS settings ('cors'
, 'no-cors'
, 'same-origin'
)cache
, redirect
, credentials
, etc.response.status
→ HTTP status code (e.g., 200
, 404
)response.ok
→ true
if status is between 200–299response.headers
→ Readable headers object (limited access client-side)fetch()
only throws an error on network failures You must check response.ok
manually.Method | Purpose |
---|---|
response.blob() |
Binary file like images |
response.arrayBuffer() |
Low-level binary (audio, video) |
response.body |
A ReadableStream for chunked reading [LARGE FILES] |
Some headers like Cookie
, Referer
, and Origin
are controlled by the browser and cannot be set manually.
JSON.stringify()
): Most common in APIs