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
fetch(url, type)
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
>
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)
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.
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
Defined in
projects/utilities/packages/fetch/src/lib/fetch.ts:16
fetch(url, options, type)
fetch<
R
>(url
:string
|URL
,options
:RequestOptions
,type
?:JSON
):Promise
<R
>
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 |