Module: @sapphire/fetch
Enumerations
Classes
Interfaces
Functions
fetch
▸ fetch<R
>(url
, type?
): Promise
<R
>
Performs an HTTP(S) fetch
Type parameters
Name |
---|
R |
Parameters
Name | Type | Description |
---|---|---|
url | string | URL | 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 . |
type? | JSON | Only 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 isunknown
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 beBuffer
. - When using
FetchResultTypes.Blob
the return type will be aBlob
. - When using
FetchResultTypes.Text
the return type will be astring
- When using
FetchResultTypes.Result
the return type will be aResponse
(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
Name | Type |
---|---|
url | string | URL |
options | RequestOptions |
type? | JSON |
Returns
Promise
<R
>
Defined in
projects/utilities/packages/fetch/src/lib/fetch.ts:22
▸ fetch(url
, type
): Promise
<Buffer
>
Parameters
Name | Type |
---|---|
url | string | URL |
type | Buffer |
Returns
Promise
<Buffer
>
Defined in
projects/utilities/packages/fetch/src/lib/fetch.ts:23
▸ fetch(url
, options
, type
): Promise
<Buffer
>
Parameters
Name | Type |
---|---|
url | string | URL |
options | RequestOptions |
type | Buffer |
Returns
Promise
<Buffer
>
Defined in
projects/utilities/packages/fetch/src/lib/fetch.ts:24
▸ fetch(url
, type
): Promise
<Blob
>
Parameters
Name | Type |
---|---|
url | string | URL |
type | Blob |
Returns
Defined in
projects/utilities/packages/fetch/src/lib/fetch.ts:25
▸ fetch(url
, options
, type
): Promise
<Blob
>
Parameters
Name | Type |
---|---|
url | string | URL |
options | RequestOptions |
type | Blob |
Returns
Defined in
projects/utilities/packages/fetch/src/lib/fetch.ts:26
▸ fetch(url
, type
): Promise
<string
>
Parameters
Name | Type |
---|---|
url | string | URL |
type | Text |
Returns
Promise
<string
>
Defined in
projects/utilities/packages/fetch/src/lib/fetch.ts:27
▸ fetch(url
, options
, type
): Promise
<string
>
Parameters
Name | Type |
---|---|
url | string | URL |
options | RequestOptions |
type | Text |
Returns
Promise
<string
>
Defined in
projects/utilities/packages/fetch/src/lib/fetch.ts:28
▸ fetch(url
, type
): Promise
<Response
>
Parameters
Name | Type |
---|---|
url | string | URL |
type | Result |
Returns
Defined in
projects/utilities/packages/fetch/src/lib/fetch.ts:29
▸ fetch(url
, options
, type
): Promise
<Response
>
Parameters
Name | Type |
---|---|
url | string | URL |
options | RequestOptions |
type | Result |
Returns
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
Name | Type |
---|---|
url | string | URL |
options | RequestOptions |
type | FetchResultTypes |
Returns
Promise
<Response
| Blob
| Buffer
| string
| R
>