@lodestar/api
Version:
A Typescript REST client for the Ethereum Consensus API
48 lines • 1.98 kB
TypeScript
import { Logger, fetch } from "@lodestar/utils";
import { Endpoint } from "../types.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>>;
private requestWithFallbacks;
private requestWithRetries;
private requestFallbackToJson;
private _request;
private getRequestMethod;
}
//# sourceMappingURL=httpClient.d.ts.map