Fetch
Functions
Fetch a resource from the network. It returns a Promise that resolves to the
Response to that Request, whether it is successful or not.
Interfaces
Represents a connection to a server that sends
server-sent events,
receiving updates pushed by the server as a stream of message events over a
persistent HTTP connection that automatically reconnects when interrupted.
Provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using the XMLHttpRequest.send() method. It uses the same format a form would use if the encoding type were set to "multipart/form-data".
This Fetch API interface allows you to perform various actions on HTTP request and response headers. These actions include retrieving, setting, adding to, and removing. A Headers object has an associated header list, which is initially empty and consists of zero or more name and value pairs. You can add to this using methods like append() (see Examples). In all methods of this interface, header names are matched by case-insensitive byte sequence.
This Fetch API interface represents a resource request.
Type Aliases
function fetch
Overload 1
#fetch(input: RequestInfo | URL,init?: RequestInit,): Promise<Response>Fetch a resource from the network. It returns a Promise that resolves to the
Response to that Request, whether it is successful or not.
const response = await fetch("http://my.json.host/data.json");
console.log(response.status); // e.g. 200
console.log(response.statusText); // e.g. "OK"
const jsonData = await response.json();
Parameters #
#input: RequestInfo | URL #init: RequestInit Return Type #
Promise<Response> Overload 2
#fetch(input: RequestInfo | URL,init?: RequestInit & { client?: Deno.HttpClient; },): Promise<Response>The Fetch API
which also supports setting a Deno.HttpClient which provides a
way to connect via proxies and use custom TLS certificates.
Parameters #
#input: RequestInfo | URL #init: RequestInit & { client?: Deno.HttpClient; } Return Type #
Promise<Response> interface Body
Properties #
#body: ReadableStream<Uint8Array<ArrayBuffer>> | null A simple getter used to expose a ReadableStream of the body contents.
Methods #
#arrayBuffer(): Promise<ArrayBuffer> Takes a Response stream and reads it to completion. It returns a promise
that resolves with an ArrayBuffer.
Takes a Response stream and reads it to completion. It returns a promise
that resolves with a Blob.
#bytes(): Promise<Uint8Array<ArrayBuffer>> Takes a Response stream and reads it to completion. It returns a promise
that resolves with a Uint8Array.
Takes a Response stream and reads it to completion. It returns a promise
that resolves with a FormData object.
Takes a Response stream and reads it to completion. It returns a promise
that resolves with the result of parsing the body text as JSON.
interface EventSource
Represents a connection to a server that sends
server-sent events,
receiving updates pushed by the server as a stream of message events over a
persistent HTTP connection that automatically reconnects when interrupted.
Properties #
#onerror: ((this: EventSource,ev: Event,) => any) | null #onmessage: ((this: EventSource,ev: MessageEvent,) => any) | null #onopen: ((this: EventSource,ev: Event,) => any) | null #readyState: number Returns the state of this EventSource object's connection. It can have the values described below.
#withCredentials: boolean Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
#CONNECTING: 0 Methods #
Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
#addEventListener<K extends keyof EventSourceEventMap>(type: K,listener: (this: EventSource,ev: EventSourceEventMap[K],) => any,options?: boolean | AddEventListenerOptions,): void #addEventListener(type: string,listener: (this: EventSource,event: MessageEvent,) => any,options?: boolean | AddEventListenerOptions,): void #addEventListener(type: string,listener: EventListenerOrEventListenerObject,options?: boolean | AddEventListenerOptions,): void #removeEventListener<K extends keyof EventSourceEventMap>(type: K,listener: (this: EventSource,ev: EventSourceEventMap[K],) => any,options?: boolean | EventListenerOptions,): void #removeEventListener(type: string,listener: (this: EventSource,event: MessageEvent,) => any,options?: boolean | EventListenerOptions,): void #removeEventListener(): void variable EventSource
The EventSource interface is a web content's interface to server-sent
events. An EventSource instance opens a persistent connection to an HTTP
server, which sends events in text/event-stream format. The connection
remains open until closed by calling EventSource.close.
Properties #
See #
interface EventSourceInit
Properties #
#withCredentials: boolean #headers: HeadersInit interface FormData
Provides a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using the XMLHttpRequest.send() method. It uses the same format a form would use if the encoding type were set to "multipart/form-data".
Methods #
interface Headers
This Fetch API interface allows you to perform various actions on HTTP request and response headers. These actions include retrieving, setting, adding to, and removing. A Headers object has an associated header list, which is initially empty and consists of zero or more name and value pairs. You can add to this using methods like append() (see Examples). In all methods of this interface, header names are matched by case-insensitive byte sequence.
Methods #
Appends a new value onto an existing header inside a Headers object, or
adds the header if it does not already exist.
Returns a ByteString sequence of all the values of a header within a
Headers object with a given name.
Returns a boolean stating whether a Headers object contains a certain
header.
Sets a new value for an existing header inside a Headers object, or adds the header if it does not already exist.
#getSetCookie(): string[] Returns an array containing the values of all Set-Cookie headers
associated with a response.
variable Headers
This Fetch API interface allows you to perform various actions on HTTP request and response headers. These actions include retrieving, setting, adding to, and removing. A Headers object has an associated header list, which is initially empty and consists of zero or more name and value pairs. You can add to this using methods like append() (see Examples). In all methods of this interface, header names are matched by case-insensitive byte sequence.
Properties #
interface Request
This Fetch API interface represents a resource request.
Properties #
#cache: RequestCache Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching.
#credentials: RequestCredentials Returns the credentials mode associated with request, which is a string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL.
#destination: RequestDestination Returns the kind of resource requested by request, e.g., "document" or "script".
Returns a Headers object consisting of the headers associated with request. Note that headers added in the network layer by the user agent will not be accounted for in this object, e.g., the "Host" header.
Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI]
Returns a boolean indicating whether or not request can outlive the global in which it was created.
#mode: RequestMode Returns the mode associated with request, which is a string indicating whether the request will use CORS, or will be restricted to same-origin URLs.
#redirect: RequestRedirect Returns the redirect mode associated with request, which is a string indicating how redirects for the request will be handled during fetching. A request will follow redirects by default.
Returns the referrer of request. Its value can be a same-origin URL if
explicitly set in init, the empty string to indicate no referrer, and
"about:client" when defaulting to the global's default. This is used during
fetching to determine the value of the Referer header of the request
being made.
#referrerPolicy: ReferrerPolicy Returns the referrer policy associated with request. This is used during fetching to compute the value of the request's referrer.
#signal: AbortSignal Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler.
Methods #
interface RequestInit
Properties #
#cache: RequestCache A string indicating how the request will interact with the browser's cache to set request's cache.
#credentials: RequestCredentials A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials.
#headers: HeadersInit A Headers object, an object literal, or an array of two-item arrays to set request's headers.
A cryptographic hash of the resource to be fetched by request. Sets request's integrity.
#mode: RequestMode A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request's mode.
#priority: RequestPriority A string indicating the relative priority of the request. Sets request's priority.
#redirect: RequestRedirect A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect.
A string whose value is a same-origin URL, "about:client", or the empty string, to set request's referrer.
#referrerPolicy: ReferrerPolicy A referrer policy to set request's referrerPolicy.
#signal: AbortSignal | null An AbortSignal to set request's signal.
interface ResponseInit
Properties #
type alias BodyInit
Definition #
Blob
| BufferSource
| FormData
| URLSearchParams
| ReadableStream<Uint8Array>
| Iterable<Uint8Array>
| AsyncIterable<Uint8Array>
| string type alias FormDataEntryValue
type alias HeadersInit
Definition #
Iterable<string[]> | Record<string, string> type alias ReferrerPolicy
Definition #
""
| "no-referrer"
| "no-referrer-when-downgrade"
| "origin"
| "origin-when-cross-origin"
| "same-origin"
| "strict-origin"
| "strict-origin-when-cross-origin"
| "unsafe-url" type alias RequestCache
Definition #
"default"
| "force-cache"
| "no-cache"
| "no-store"
| "only-if-cached"
| "reload" type alias RequestCredentials
Definition #
"include"
| "omit"
| "same-origin" type alias RequestDestination
Definition #
""
| "audio"
| "audioworklet"
| "document"
| "embed"
| "font"
| "image"
| "manifest"
| "object"
| "paintworklet"
| "report"
| "script"
| "sharedworker"
| "style"
| "track"
| "video"
| "worker"
| "xslt" type alias RequestInfo
type alias RequestMode
Definition #
"cors"
| "navigate"
| "no-cors"
| "same-origin" type alias RequestPriority
Definition #
"auto"
| "high"
| "low" type alias RequestRedirect
Definition #
"error"
| "follow"
| "manual" type alias ResponseType
Definition #
"basic"
| "cors"
| "default"
| "error"
| "opaque"
| "opaqueredirect"