node-tls-clientLatest version on npm

fetch()

Send one request in a throwaway session.

import { fetch, ClientIdentifier } from "node-tls-client";

const res = await fetch("https://httpbin.org/get", {
  options: { clientIdentifier: ClientIdentifier.firefox_148, timeout: 5000 },
});
fetch(url: string, options?: fetchOptions): Promise<Response>

Creates a Session from options.options, sends one request, closes the session and resolves with the Response. initTLS() must have been called first.

Use it when each request needs different session settings (a different timeout, profile or insecureSkipVerify). For several requests to the same site, use a Session: it keeps cookies and connections between requests, and fetch() doesn't.

  • method defaults to "GET" and is case-insensitive. Anything other than GET, POST, PUT, DELETE, PATCH, OPTIONS or HEAD rejects with a TlsClientError.
  • Errors are rethrown as TlsClientError.
  • The session is closed even when the request fails.

fetchOptions

FieldTypeDescription
method?MethodsRequest method.
headers?HeaderInputThe headers for the request.
body?string | Buffer | Uint8Array | nullThe body of the request (string, or Buffer for binary payloads).
followRedirects?booleanWhether to follow redirects.
proxy?stringThe proxy server to use for the request.
isRotatingProxy?booleanWhether proxy is rotating proxy or not.
cookies?Record<string, string | number>Cookies for the request.
options?SessionOptionsAdditional session options.

On this page