UNPKG

@lodestar/api

Version:

A Typescript REST client for the Ethereum Consensus API

63 lines 2.49 kB
import { Logger } from "@lodestar/utils"; import { Endpoint } from "../types.js"; import { fetch } from "./fetch.js"; import { Metrics } from "./metrics.js"; import { ApiRequestInit, ExtraRequestInit, RouteDefinitionExtra, UrlInit, UrlInitRequired } from "./request.js"; import { ApiResponse } from "./response.js"; export declare const defaultInit: Required<ExtraRequestInit>; export interface IHttpClient { readonly baseUrl: string; readonly urlsInits: UrlInitRequired[]; readonly urlsScore: number[]; request<E extends Endpoint>(definition: RouteDefinitionExtra<E>, args: E["args"], localInit?: ApiRequestInit): Promise<ApiResponse<E>>; } export type HttpClientOptions = ({ baseUrl: string; } | { urls: (string | UrlInit)[]; }) & { globalInit?: ApiRequestInit; /** Override fetch function */ fetch?: typeof fetch; }; export type HttpClientModules = { logger?: Logger; metrics?: Metrics; }; export declare class HttpClient implements IHttpClient { readonly urlsInits: UrlInitRequired[]; readonly urlsScore: number[]; private readonly signal; private readonly fetch; private readonly metrics; private readonly logger; /** * Cache to keep track of routes per server that do not support SSZ. This cache will only be * populated if we receive a 415 error response from the server after sending a SSZ request body. * The request will be retried using a JSON body and all subsequent requests will only use JSON. */ private readonly sszNotSupportedByRouteIdByUrlIndex; get baseUrl(): string; constructor(opts: HttpClientOptions, { logger, metrics }?: HttpClientModules); request<E extends Endpoint>(definition: RouteDefinitionExtra<E>, args: E["args"], localInit?: ApiRequestInit): Promise<ApiResponse<E>>; /** * Send request to primary server first, retry failed requests on fallbacks */ private requestWithFallbacks; /** * Send request to single URL, retry failed requests on same server */ private requestWithRetries; /** * Send request to single URL, SSZ requests will be retried using JSON * if a 415 error response is returned by the server. All subsequent requests * to this server for the route will always be sent as JSON afterwards. */ private requestFallbackToJson; /** * Send request to single URL */ private _request; private getRequestMethod; } //# sourceMappingURL=httpClient.d.ts.map