Skip to main content

Module: @sapphire/fetch

Enumerations

Classes

Interfaces

Functions

fetch

fetch<R>(url, type?): Promise<R>

Performs an HTTP(S) fetch

Type parameters

Name
R

Parameters

NameTypeDescription
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?JSONOnly needs to be provided if the second parameter are Request options (RequestInit for TypeScript). One of the FetchResultTypes that will determine how the result is returned.

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)

Defined in

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

fetch<R>(url, options, type?): Promise<R>

Type parameters

Name
R

Parameters

NameType
urlstring | URL
optionsRequestOptions
type?JSON

Returns

Promise<R>

Defined in

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

fetch(url, type): Promise<Buffer>

Parameters

NameType
urlstring | URL
typeBuffer

Returns

Promise<Buffer>

Defined in

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

fetch(url, options, type): Promise<Buffer>

Parameters

NameType
urlstring | URL
optionsRequestOptions
typeBuffer

Returns

Promise<Buffer>

Defined in

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

fetch(url, type): Promise<Blob>

Parameters

NameType
urlstring | URL
typeBlob

Returns

Promise<Blob>

Defined in

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

fetch(url, options, type): Promise<Blob>

Parameters

NameType
urlstring | URL
optionsRequestOptions
typeBlob

Returns

Promise<Blob>

Defined in

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

fetch(url, type): Promise<string>

Parameters

NameType
urlstring | URL
typeText

Returns

Promise<string>

Defined in

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

fetch(url, options, type): Promise<string>

Parameters

NameType
urlstring | URL
optionsRequestOptions
typeText

Returns

Promise<string>

Defined in

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

fetch(url, type): Promise<Response>

Parameters

NameType
urlstring | URL
typeResult

Returns

Promise<Response>

Defined in

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

fetch(url, options, type): Promise<Response>

Parameters

NameType
urlstring | URL
optionsRequestOptions
typeResult

Returns

Promise<Response>

Defined in

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

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

Type parameters

Name
R

Parameters

NameType
urlstring | URL
optionsRequestOptions
typeFetchResultTypes

Returns

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

Defined in

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