Ende.createHttpClient

function

function Ende.createHttpClient(options: CreateHttpClientOptions | (CreateHttpClientOptions & TlsCertifiedKeyPem)): HttpClient

Create a custom HttpClient to use with fetch. This is an extension of the web platform Fetch API which allows Ende 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.

Example

const caCert = await Ende.readTextFile("./ca.pem");
const client = Ende.createHttpClient({ caCerts: [ caCert ] });
const response = await fetch("https://myserver.com", { client });

Example

const client = Ende.createHttpClient({
  proxy: { url: "http://myproxy.com:8080" }
});
const response = await fetch("https://myserver.com", { client });

Example

const key = "----BEGIN PRIVATE KEY----...";
const cert = "----BEGIN CERTIFICATE----...";
const client = Ende.createHttpClient({ key, cert });
const response = await fetch("https://myserver.com", { client });