Fetch
HTTP client for fetching data across a network. Retrieve resources from servers, handle responses, and manage network requests.
Eg fetch, Response, Request, Headers
Classes
A custom HttpClient for use with fetch function. This is
designed to allow custom certificates or proxies to be used with fetch().
Functions
Create a custom HttpClient to use with fetch. This is an
extension of the web platform Fetch API which allows Deno to use custom
TLS CA certificates and connect via a proxy while using fetch().
Interfaces
Basic authentication credentials to be used with a Deno.Proxy
server when specifying Deno.CreateHttpClientOptions.
The options used when creating a Deno.HttpClient.
Type Aliases
class Deno.HttpClient
A custom HttpClient for use with fetch function. This is
designed to allow custom certificates or proxies to be used with fetch().
Examples #
const caCert = await Deno.readTextFile("./ca.pem");
const client = Deno.createHttpClient({ caCerts: [ caCert ] });
const req = await fetch("https://myserver.com", { client });
Methods #
#[Symbol.dispose](): void function Deno.createHttpClient
#createHttpClient(options: CreateHttpClientOptions | (CreateHttpClientOptions & TlsCertifiedKeyPem)): HttpClientCreate a custom HttpClient to use with fetch. This is an
extension of the web platform Fetch API which allows Deno to use custom
TLS CA certificates and connect via a proxy while using fetch().
The cert and key options can be used to specify a client certificate
and key to use when connecting to a server that requires client
authentication (mutual TLS or mTLS). The cert and key options must be
provided in PEM format.
Examples #
const caCert = await Deno.readTextFile("./ca.pem");
const client = Deno.createHttpClient({ caCerts: [ caCert ] });
const response = await fetch("https://myserver.com", { client });
const client = Deno.createHttpClient({
proxy: { url: "http://myproxy.com:8080" }
});
const response = await fetch("https://myserver.com", { client });
const key = "----BEGIN PRIVATE KEY----...";
const cert = "----BEGIN CERTIFICATE----...";
const client = Deno.createHttpClient({ key, cert });
const response = await fetch("https://myserver.com", { client });
Parameters #
#options: CreateHttpClientOptions | (CreateHttpClientOptions & TlsCertifiedKeyPem) Return Type #
interface Deno.BasicAuth
Basic authentication credentials to be used with a Deno.Proxy
server when specifying Deno.CreateHttpClientOptions.
Properties #
interface Deno.CreateHttpClientOptions
The options used when creating a Deno.HttpClient.
Properties #
A list of root certificates that will be used in addition to the default root certificates to verify the peer's certificate.
Must be in PEM format.
#poolMaxIdlePerHost: number Sets the maximum number of idle connections per host allowed in the pool.
#poolIdleTimeout: number | false Set an optional timeout for idle sockets being kept-alive. Set to false to disable the timeout.
#localAddress: string Sets the local address where the socket will connect from.
type alias Deno.Proxy
The definition for alternative transports (or proxies) in
Deno.CreateHttpClientOptions.
Supported proxies:
- HTTP/HTTPS proxy: this uses passthrough to tunnel HTTP requests, or HTTP CONNECT to tunnel HTTPS requests through a different server.
- SOCKS5 proxy: this uses the SOCKS5 protocol to tunnel TCP connections through a different server.
- TCP socket: this sends all requests to a specified TCP socket.
- Unix domain socket: this sends all requests to a local Unix domain socket rather than a TCP socket. Not supported on Windows.
- Vsock socket: this sends all requests to a local vsock socket. Only supported on Linux and macOS.
Definition #
{ transport?: "http"
| "https"
| "socks5"; url: string; basicAuth?: BasicAuth; }
| { transport: "tcp"; hostname: string; port: number; }
| { transport: "unix"; path: string; }
| { transport: "vsock"; cid: number; port: number; } 