Web - Fetch API
> (World Wide) Web - (W3|WWW) > (HTTP|HTTPS) - Hypertext Transfer Protocol
Table of Contents
1 - About
The fetch function is a promise.
2 - Articles Related
Advertising
3 - Syntax
fetch(url, { body: JSON.stringify(data), // must match 'Content-Type' header cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached credentials: 'same-origin', // include, *omit headers: { 'user-agent': 'Mozilla/4.0 MDN Example', 'content-type': 'application/json' }, method: 'POST', // *GET, PUT, DELETE, etc. mode: 'cors', // no-cors, *same-origin redirect: 'follow', // *manual, error referrer: 'no-referrer', // *client credentials: 'same-origin' }) .then(response => response.json()) // parses response to JSON
3.1 - Credentials
Credentials are HTTP cookies, TLS client certificates, and authentication entries (for HTTP authentication). For CORS requests, use the “include” value to allow sending credentials to other domains:
3.2 - Mode
- Using mode: “no-cors” will give you an opaque response, which doesn't seem to return data in the body. See Opaque Response