Skip to main content

Function: fetch()

Performs an HTTP(S) fetch

Param

The 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.

Param

The `Request` (RequestInit for TypeScript)

Param

The FetchResultTypes

Call Signature

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

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

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>

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)

Param

The 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.

Param

The `Request` (RequestInit for TypeScript)

Param

The FetchResultTypes

Call Signature

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

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

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>

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)

Param

The 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.

Param

The `Request` (RequestInit for TypeScript)

Param

The FetchResultTypes

Call Signature

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

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

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>

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)

Param

The 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.

Param

The `Request` (RequestInit for TypeScript)

Param

The FetchResultTypes

Call Signature

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

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

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>

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)

Param

The 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.

Param

The `Request` (RequestInit for TypeScript)

Param

The FetchResultTypes

Call Signature

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

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

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>

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)

Param

The 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.

Param

The `Request` (RequestInit for TypeScript)

Param

The FetchResultTypes

Call Signature

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

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

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>

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)

Param

The 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.

Param

The `Request` (RequestInit for TypeScript)

Param

The FetchResultTypes

Call Signature

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

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

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 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)

Param

The 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.

Param

The `Request` (RequestInit for TypeScript)

Param

The FetchResultTypes

Call Signature

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

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

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 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)

Param

The 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.

Param

The `Request` (RequestInit for TypeScript)

Param

The FetchResultTypes

Call Signature

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

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

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 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)

Param

The 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.

Param

The `Request` (RequestInit for TypeScript)

Param

The FetchResultTypes

Call Signature

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

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

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 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)

Param

The 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.

Param

The `Request` (RequestInit for TypeScript)

Param

The FetchResultTypes

Call Signature

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

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

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<string | Blob | Response | R | Buffer>

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)

Param

The 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.

Param

The `Request` (RequestInit for TypeScript)

Param

The FetchResultTypes