WHATWG Fetch implementation for Bare.
npm i bare-fetch
const fetch = require('bare-fetch')
const res = await fetch('https://example.com/data')
console.log(await res.json())Perform an HTTP or HTTPS request. input may be a URL string, a URL object, or a Request object. init is an optional options object.
Options include:
init = {
body: null,
method: 'GET',
headers: new Headers(),
signal: null,
agent: null
}Redirects are followed automatically up to a maximum of 20. When crossing origins, the authorization header is removed. If signal is provided, the request can be aborted using an AbortController.
The Request class. See below.
The Response class. See below.
The Headers class. See below.
Create a new request. input may be a URL string, a URL object, or another Request object. init is an optional options object, identical to the one accepted by fetch().
The request URL as a string.
The request method. Standard methods (GET, POST, PUT, DELETE, HEAD, OPTIONS) are uppercased automatically.
The request headers as a Headers object.
The abort signal associated with the request, or null.
The request body as a ReadableStream, or null.
Whether the body stream has already been consumed.
Consume the body and return a Buffer.
Consume the body and return a Uint8Array.
Consume the body and return an ArrayBuffer.
Consume the body and return a UTF-8 string.
Consume the body and return a parsed JSON value.
Consume the body and return a FormData object. Supports multipart/form-data and application/x-www-form-urlencoded content types.
Clone the request. Throws if the body has already been consumed.
The final response URL as a string, or null if no request has been made.
Whether the request was redirected to a different URL.
The HTTP status code of the response.
Whether the status code is in the range 200-299.
The HTTP status message of the response.
The response headers as a Headers object.
The response body as a ReadableStream, or null.
Whether the body stream has already been consumed.
Consume the body and return a Buffer.
Consume the body and return a Uint8Array.
Consume the body and return an ArrayBuffer.
Consume the body and return a UTF-8 string.
Consume the body and return a parsed JSON value.
Consume the body and return a FormData object. Supports multipart/form-data and application/x-www-form-urlencoded content types.
Clone the response. Throws if the body has already been consumed.
Create a new headers object. init may be a plain object, an iterable of [name, value] pairs, or another Headers instance.
Append a value to the header name. If the header already exists, the value is added to the existing list.
Delete the header name.
Get the value of the header name as a comma-separated string, or null if it does not exist.
Return whether the header name exists.
Set the header name to value, replacing any existing values.
Return an iterator over [name, value] pairs.
Return an iterator over header names.
Return an iterator over header values.
Call callback for each header with the arguments (value, name, headers).
Apache-2.0