What RequestInit is
The second argument to fetch(input, init) is a RequestInit dictionary. Every
field is optional, and the defaults are tuned for the common case of a simple
same-page GET. Knowing the defaults matters: many subtle bugs — a cookie that
never sends, a cross-origin response you cannot read, a stale cached body — come
down to an option left at its default when you needed to override it.
How it works
When you call fetch, the browser merges your init object with the defaults to
build a Request. The fields fall into a few groups: request line (method,
body), headers (headers), security and network policy (mode,
credentials, referrerPolicy, redirect), caching (cache), lifecycle
(signal, keepalive, priority), and integrity (integrity). The reference
below lists each field with its type, default, and the gotcha most likely to bite
you, plus a builder that assembles a real init object from your selections.
Tips and notes
Three defaults trip people up most often: mode is cors so cross-origin reads
need server CORS headers; credentials is same-origin so cookies do not
ride along cross-origin unless you set include; and redirect is follow so a
30x is transparently chased. Use cache: 'no-store' to truly bypass the HTTP
cache, an AbortController signal to cancel, and keepalive for beacons sent
during page unload.