Javascript Fetch Api – All Documentation

Hi, I’m Guillermo Antony Cava Nunez, every morning I check content to improve on my work flow, either adopt new tech or stay away. Recently while making a dashboard I noticed that I haven’t made much use of the javascript fetch api, and well this documentation made my life easier, hope you guys benefit!

This documents the polyfillable parts of the WHATWG Fetch standard. See Caveats for notable exceptions.

Usage synopsis (use the argument links to find out more):

fetch(url, options).then(
	function (response) {
		// handle HTTP response
	},
	function (error) {
		// handle network error
	},
)

More comprehensive usage example:

fetch(url, {
	method: 'POST',
	body: JSON.stringify(data),
	headers: {
		'Content-Type': 'application/json',
	},
	credentials: 'same-origin',
}).then(
	function (response) {
		response.status //=> number 100–599
		response.statusText //=> String
		response.headers //=> Headers
		response.url //=> String

		return response.text()
	},
	function (error) {
		error.message //=> String
	},
)

Request

Synopsis: new Request([url](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#input), [options](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options))

Request represents a HTTP request to be performed via fetch(). Typically a Request doesn’t need to be constructed manually, as it’s instantiated internally when fetch() is called.

URL (Request or string)