Skip to main content

Module: @sapphire/fetch

Enumerations

Classes

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 ({@link 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 ({@link 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
optionsRequestInit
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
optionsRequestInit
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
optionsRequestInit
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
optionsRequestInit
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
optionsRequestInit
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
optionsRequestInit
typeFetchResultTypes

Returns

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

Defined in

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