Skip to main content

Function: fetch()

fetch(url, type)

fetch<R>(url: string | URL, type?: JSON): Promise<R>

Performs an HTTP(S) fetch

Type parameters

Type parameter
R

Parameters

ParameterTypeDescription
urlstring | URLThe URL to send the request to. Can be either a string or an URL object. url should be an absolute url, such as https://example.com/. A path-relative URL (/file/under/root) or protocol-relative URL (//can-be-http-or-https.com/) will result in a rejected Promise.
type?JSONThe FetchResultTypes

Returns

Promise<R>

A JSON of the response body. Defaults to unknown, with the type set by passing the generic type of this function, or casting the result.

Source

projects/utilities/packages/fetch/src/lib/fetch.ts:16

fetch(url, options, type)

fetch<R>(url: string | URL, options: RequestOptions, type?: JSON): Promise<R>

Performs an HTTP(S) fetch

Type parameters

Type parameter
R

Parameters

ParameterTypeDescription
urlstring | URLThe URL to send the request to. Can be either a string or an URL object. url should be an absolute url, such as https://example.com/. A path-relative URL (/file/under/root) or protocol-relative URL (//can-be-http-or-https.com/) will result in a rejected Promise.
optionsRequestOptionsThe Request (RequestInit for TypeScript)
type?JSONThe FetchResultTypes

Returns

Promise<R>

A JSON of the response body. Defaults to unknown, with the type set by passing the generic type of this function, or casting the result.

Source

projects/utilities/packages/fetch/src/lib/fetch.ts:27

fetch(url, type)

fetch(url: string | URL, type: Buffer): Promise<Buffer>

Performs an HTTP(S) fetch

Parameters

ParameterTypeDescription
urlstring | URLThe URL to send the request to. Can be either a string or an URL object. url should be an absolute url, such as https://example.com/. A path-relative URL (/file/under/root) or protocol-relative URL (//can-be-http-or-https.com/) will result in a rejected Promise.
typeBufferThe FetchResultTypes

Returns

Promise<Buffer>

A Buffer of the response body

Source

projects/utilities/packages/fetch/src/lib/fetch.ts:37

fetch(url, options, type)

fetch(url: string | URL, options: RequestOptions, type: Buffer): Promise<Buffer>

Performs an HTTP(S) fetch

Parameters

ParameterTypeDescription
urlstring | URLThe URL to send the request to. Can be either a string or an URL object. url should be an absolute url, such as https://example.com/. A path-relative URL (/file/under/root) or protocol-relative URL (//can-be-http-or-https.com/) will result in a rejected Promise.
optionsRequestOptionsThe Request (RequestInit for TypeScript)
typeBufferThe FetchResultTypes

Returns

Promise<Buffer>

A Buffer of the response body

Source

projects/utilities/packages/fetch/src/lib/fetch.ts:48

fetch(url, type)

fetch(url: string | URL, type: Blob): Promise <Blob>

Performs an HTTP(S) fetch

Parameters

ParameterTypeDescription
urlstring | URLThe URL to send the request to. Can be either a string or an URL object. url should be an absolute url, such as https://example.com/. A path-relative URL (/file/under/root) or protocol-relative URL (//can-be-http-or-https.com/) will result in a rejected Promise.
typeBlobThe FetchResultTypes

Returns

Promise <Blob>

A Blob of the response body

Source

projects/utilities/packages/fetch/src/lib/fetch.ts:58

fetch(url, options, type)

fetch(url: string | URL, options: RequestOptions, type: Blob): Promise <Blob>

Performs an HTTP(S) fetch

Parameters

ParameterTypeDescription
urlstring | URLThe URL to send the request to. Can be either a string or an URL object. url should be an absolute url, such as https://example.com/. A path-relative URL (/file/under/root) or protocol-relative URL (//can-be-http-or-https.com/) will result in a rejected Promise.
optionsRequestOptionsThe Request (RequestInit for TypeScript)
typeBlobThe FetchResultTypes

Returns

Promise <Blob>

A Blob of the response body

Source

projects/utilities/packages/fetch/src/lib/fetch.ts:69

fetch(url, type)

fetch(url: string | URL, type: Text): Promise<string>

Performs an HTTP(S) fetch

Parameters

ParameterTypeDescription
urlstring | URLThe URL to send the request to. Can be either a string or an URL object. url should be an absolute url, such as https://example.com/. A path-relative URL (/file/under/root) or protocol-relative URL (//can-be-http-or-https.com/) will result in a rejected Promise.
typeTextThe FetchResultTypes

Returns

Promise<string>

The response body as a raw string.

Source

projects/utilities/packages/fetch/src/lib/fetch.ts:79

fetch(url, options, type)

fetch(url: string | URL, options: RequestOptions, type: Text): Promise<string>

Performs an HTTP(S) fetch

Parameters

ParameterTypeDescription
urlstring | URLThe URL to send the request to. Can be either a string or an URL object. url should be an absolute url, such as https://example.com/. A path-relative URL (/file/under/root) or protocol-relative URL (//can-be-http-or-https.com/) will result in a rejected Promise.
optionsRequestOptionsThe Request (RequestInit for TypeScript)
typeTextThe FetchResultTypes

Returns

Promise<string>

The response body as a raw string.

Source

projects/utilities/packages/fetch/src/lib/fetch.ts:90

fetch(url, type)

fetch(url: string | URL, type: Result): Promise <Response>

Performs an HTTP(S) fetch

Parameters

ParameterTypeDescription
urlstring | URLThe URL to send the request to. Can be either a string or an URL object. url should be an absolute url, such as https://example.com/. A path-relative URL (/file/under/root) or protocol-relative URL (//can-be-http-or-https.com/) will result in a rejected Promise.
typeResultThe FetchResultTypes

Returns

Promise <Response>

The raw Response (Response in typescript).

Source

projects/utilities/packages/fetch/src/lib/fetch.ts:100

fetch(url, options, type)

fetch(url: string | URL, options: RequestOptions, type: Result): Promise <Response>

Performs an HTTP(S) fetch

Parameters

ParameterTypeDescription
urlstring | URLThe URL to send the request to. Can be either a string or an URL object. url should be an absolute url, such as https://example.com/. A path-relative URL (/file/under/root) or protocol-relative URL (//can-be-http-or-https.com/) will result in a rejected Promise.
optionsRequestOptionsThe Request (RequestInit for TypeScript)
typeResultThe FetchResultTypes

Returns

Promise <Response>

The raw Response (Response in typescript).

Source

projects/utilities/packages/fetch/src/lib/fetch.ts:111

fetch(url, options, type)

fetch<R>(url: string | URL, options: RequestOptions, type: FetchResultTypes): Promise <Response | Blob | Buffer | string | R>

Performs an HTTP(S) fetch

Type parameters

Type parameter
R

Parameters

ParameterTypeDescription
urlstring | URLThe URL to send the request to. Can be either a string or an URL object. url should be an absolute url, such as https://example.com/. A path-relative URL (/file/under/root) or protocol-relative URL (//can-be-http-or-https.com/) will result in a rejected Promise.
optionsRequestOptionsThe Request (RequestInit for TypeScript)
typeFetchResultTypesThe FetchResultTypes

Returns

Promise <Response | Blob | Buffer | string | R>

The return type is determined by the provided type.

  • When using FetchResultTypes.JSON then the return type is unknown by default. The type should be specified by filling in the generic type of the function, or casting the result.
  • When using FetchResultTypes.Buffer the return type will be Buffer.
  • When using FetchResultTypes.Blob the return type will be a Blob.
  • When using FetchResultTypes.Text the return type will be a string
  • When using FetchResultTypes.Result the return type will be a Response (Response in typescript)

Source

projects/utilities/packages/fetch/src/lib/fetch.ts:127