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
Defined in: projects/utilities/packages/fetch/src/lib/fetch.ts:16
Performs an HTTP(S) fetch
Type Parameters
| Type Parameter |
|---|
R |
Parameters
| Parameter | 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 | The 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.
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
| Parameter | 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. |
options | RequestOptions | The `Request` (RequestInit for TypeScript) |
type? | JSON | The 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.
Call Signature
Defined in: projects/utilities/packages/fetch/src/lib/fetch.ts:37
Performs an HTTP(S) fetch
Parameters
| Parameter | 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 | Buffer | The FetchResultTypes |
Returns
Promise<Buffer>
A `Buffer` of the response body
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
| Parameter | 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. |
options | RequestOptions | The `Request` (RequestInit for TypeScript) |
type | Buffer | The FetchResultTypes |
Returns
Promise<Buffer>
A `Buffer` of the response body
Call Signature
Defined in: projects/utilities/packages/fetch/src/lib/fetch.ts:58
Performs an HTTP(S) fetch
Parameters
| Parameter | 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 | Blob | The FetchResultTypes |
Returns
A `Blob` of the response body
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
| Parameter | 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. |
options | RequestOptions | The `Request` (RequestInit for TypeScript) |
type | Blob | The FetchResultTypes |
Returns
A `Blob` of the response body
Call Signature
Defined in: projects/utilities/packages/fetch/src/lib/fetch.ts:79
Performs an HTTP(S) fetch
Parameters
| Parameter | 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 | Text | The FetchResultTypes |
Returns
Promise<string>
The response body as a raw string.
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
| Parameter | 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. |
options | RequestOptions | The `Request` (RequestInit for TypeScript) |
type | Text | The FetchResultTypes |
Returns
Promise<string>
The response body as a raw string.
Call Signature
Defined in: projects/utilities/packages/fetch/src/lib/fetch.ts:100
Performs an HTTP(S) fetch
Parameters
| Parameter | 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 | Result | The FetchResultTypes |
Returns
The raw `Response` (Response in typescript).
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
| Parameter | 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. |
options | RequestOptions | The `Request` (RequestInit for TypeScript) |
type | Result | The FetchResultTypes |
Returns
The raw `Response` (Response in typescript).
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
| Parameter | 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. |
options | RequestOptions | The `Request` (RequestInit for TypeScript) |
type | FetchResultTypes | The FetchResultTypes |
Returns
Promise<string | Blob | Response | R | Buffer>
The return type is determined by the provided type.
- When using
FetchResultTypes.JSONthen the return type isunknownby default. The type should be specified by filling in the generic type of the function, or casting the result. - When using
FetchResultTypes.Bufferthe return type will be `Buffer`. - When using
FetchResultTypes.Blobthe return type will be a `Blob`. - When using
FetchResultTypes.Textthe return type will be astring - When using
FetchResultTypes.Resultthe return type will be a `Response` (Response in typescript)