/** * @since 1.0.0 */ import type * as Context from "effect/Context"; import type * as Effect from "effect/Effect"; import type { RuntimeFiber } from "effect/Fiber"; import type * as FiberRef from "effect/FiberRef"; import type { Inspectable } from "effect/Inspectable"; import type { Layer } from "effect/Layer"; import type { Pipeable } from "effect/Pipeable"; import type * as Predicate from "effect/Predicate"; import type { Ref } from "effect/Ref"; import type * as Schedule from "effect/Schedule"; import type { Scope } from "effect/Scope"; import type { NoExcessProperties, NoInfer } from "effect/Types"; import type { Cookies } from "./Cookies.js"; import type * as Error from "./HttpClientError.js"; import type * as ClientRequest from "./HttpClientRequest.js"; import type * as ClientResponse from "./HttpClientResponse.js"; /** * @since 1.0.0 * @category type ids */ export declare const TypeId: unique symbol; /** * @since 1.0.0 * @category type ids */ export type TypeId = typeof TypeId; /** * @since 1.0.0 * @category models */ export interface HttpClient extends HttpClient.With { } /** * @since 1.0.0 */ export declare namespace HttpClient { /** * @since 1.0.0 * @category models */ interface With extends Pipeable, Inspectable { readonly [TypeId]: TypeId; readonly execute: (request: ClientRequest.HttpClientRequest) => Effect.Effect; readonly get: (url: string | URL, options?: ClientRequest.Options.NoBody) => Effect.Effect; readonly head: (url: string | URL, options?: ClientRequest.Options.NoBody) => Effect.Effect; readonly post: (url: string | URL, options?: ClientRequest.Options.NoUrl) => Effect.Effect; readonly patch: (url: string | URL, options?: ClientRequest.Options.NoUrl) => Effect.Effect; readonly put: (url: string | URL, options?: ClientRequest.Options.NoUrl) => Effect.Effect; readonly del: (url: string | URL, options?: ClientRequest.Options.NoUrl) => Effect.Effect; readonly options: (url: string | URL, options?: ClientRequest.Options.NoUrl) => Effect.Effect; } /** * @since 1.0.0 * @category models */ type Preprocess = (request: ClientRequest.HttpClientRequest) => Effect.Effect; /** * @since 1.0.0 * @category models */ type Postprocess = (request: Effect.Effect) => Effect.Effect; } /** * @since 1.0.0 * @category tags */ export declare const HttpClient: Context.Tag; /** * @since 1.0.0 * @category accessors */ export declare const execute: (request: ClientRequest.HttpClientRequest) => Effect.Effect; /** * @since 1.0.0 * @category accessors */ export declare const get: (url: string | URL, options?: ClientRequest.Options.NoBody | undefined) => Effect.Effect; /** * @since 1.0.0 * @category accessors */ export declare const head: (url: string | URL, options?: ClientRequest.Options.NoBody | undefined) => Effect.Effect; /** * @since 1.0.0 * @category accessors */ export declare const post: (url: string | URL, options?: ClientRequest.Options.NoUrl | undefined) => Effect.Effect; /** * @since 1.0.0 * @category accessors */ export declare const patch: (url: string | URL, options?: ClientRequest.Options.NoUrl | undefined) => Effect.Effect; /** * @since 1.0.0 * @category accessors */ export declare const put: (url: string | URL, options?: ClientRequest.Options.NoUrl | undefined) => Effect.Effect; /** * @since 1.0.0 * @category accessors */ export declare const del: (url: string | URL, options?: ClientRequest.Options.NoUrl | undefined) => Effect.Effect; /** * @since 1.0.0 * @category accessors */ export declare const options: (url: string | URL, options?: ClientRequest.Options.NoUrl | undefined) => Effect.Effect; /** * @since 1.0.0 * @category error handling */ export declare const catchAll: { /** * @since 1.0.0 * @category error handling */ (f: (e: E) => Effect.Effect): (self: HttpClient.With) => HttpClient.With; /** * @since 1.0.0 * @category error handling */ (self: HttpClient.With, f: (e: E) => Effect.Effect): HttpClient.With; }; /** * @since 1.0.0 * @category error handling */ export declare const catchTag: { /** * @since 1.0.0 * @category error handling */ (tag: K, f: (e: Extract) => Effect.Effect): (self: HttpClient.With) => HttpClient.With, R1 | R>; /** * @since 1.0.0 * @category error handling */ (self: HttpClient.With, tag: K, f: (e: Extract) => Effect.Effect): HttpClient.With, R1 | R>; }; /** * @since 1.0.0 * @category error handling */ export declare const catchTags: { /** * @since 1.0.0 * @category error handling */ ["_tag"]]+?: (error: Extract) => Effect.Effect; } & (unknown extends E ? {} : { [K in Exclude["_tag"]>]: never; })>(cases: Cases): (self: HttpClient.With) => HttpClient.With | { [K in keyof Cases]: Cases[K] extends (...args: Array) => Effect.Effect ? E : never; }[keyof Cases], R | { [K in keyof Cases]: Cases[K] extends (...args: Array) => Effect.Effect ? R : never; }[keyof Cases]>; /** * @since 1.0.0 * @category error handling */ ["_tag"]]+?: (error: Extract) => Effect.Effect; } & (unknown extends E ? {} : { [K in Exclude["_tag"]>]: never; })>(self: HttpClient.With, cases: Cases): HttpClient.With | { [K in keyof Cases]: Cases[K] extends (...args: Array) => Effect.Effect ? E : never; }[keyof Cases], R | { [K in keyof Cases]: Cases[K] extends (...args: Array) => Effect.Effect ? R : never; }[keyof Cases]>; }; /** * Filters the result of a response, or runs an alternative effect if the predicate fails. * * @since 1.0.0 * @category filters */ export declare const filterOrElse: { /** * Filters the result of a response, or runs an alternative effect if the predicate fails. * * @since 1.0.0 * @category filters */ (predicate: Predicate.Predicate, orElse: (response: ClientResponse.HttpClientResponse) => Effect.Effect): (self: HttpClient.With) => HttpClient.With; /** * Filters the result of a response, or runs an alternative effect if the predicate fails. * * @since 1.0.0 * @category filters */ (self: HttpClient.With, predicate: Predicate.Predicate, orElse: (response: ClientResponse.HttpClientResponse) => Effect.Effect): HttpClient.With; }; /** * Filters the result of a response, or throws an error if the predicate fails. * * @since 1.0.0 * @category filters */ export declare const filterOrFail: { /** * Filters the result of a response, or throws an error if the predicate fails. * * @since 1.0.0 * @category filters */ (predicate: Predicate.Predicate, orFailWith: (response: ClientResponse.HttpClientResponse) => E2): (self: HttpClient.With) => HttpClient.With; /** * Filters the result of a response, or throws an error if the predicate fails. * * @since 1.0.0 * @category filters */ (self: HttpClient.With, predicate: Predicate.Predicate, orFailWith: (response: ClientResponse.HttpClientResponse) => E2): HttpClient.With; }; /** * Filters responses by HTTP status code. * * @since 1.0.0 * @category filters */ export declare const filterStatus: { /** * Filters responses by HTTP status code. * * @since 1.0.0 * @category filters */ (f: (status: number) => boolean): (self: HttpClient.With) => HttpClient.With; /** * Filters responses by HTTP status code. * * @since 1.0.0 * @category filters */ (self: HttpClient.With, f: (status: number) => boolean): HttpClient.With; }; /** * Filters responses that return a 2xx status code. * * @since 1.0.0 * @category filters */ export declare const filterStatusOk: (self: HttpClient.With) => HttpClient.With; /** * @since 1.0.0 * @category constructors */ export declare const makeWith: (postprocess: (request: Effect.Effect) => Effect.Effect, preprocess: HttpClient.Preprocess) => HttpClient.With; /** * @since 1.0.0 * @category constructors */ export declare const make: (f: (request: ClientRequest.HttpClientRequest, url: URL, signal: AbortSignal, fiber: RuntimeFiber) => Effect.Effect) => HttpClient; /** * @since 1.0.0 * @category mapping & sequencing */ export declare const transform: { /** * @since 1.0.0 * @category mapping & sequencing */ (f: (effect: Effect.Effect, request: ClientRequest.HttpClientRequest) => Effect.Effect): (self: HttpClient.With) => HttpClient.With; /** * @since 1.0.0 * @category mapping & sequencing */ (self: HttpClient.With, f: (effect: Effect.Effect, request: ClientRequest.HttpClientRequest) => Effect.Effect): HttpClient.With; }; /** * @since 1.0.0 * @category mapping & sequencing */ export declare const transformResponse: { /** * @since 1.0.0 * @category mapping & sequencing */ (f: (effect: Effect.Effect) => Effect.Effect): (self: HttpClient.With) => HttpClient.With; /** * @since 1.0.0 * @category mapping & sequencing */ (self: HttpClient.With, f: (effect: Effect.Effect) => Effect.Effect): HttpClient.With; }; /** * Appends a transformation of the request object before sending it. * * @since 1.0.0 * @category mapping & sequencing */ export declare const mapRequest: { /** * Appends a transformation of the request object before sending it. * * @since 1.0.0 * @category mapping & sequencing */ (f: (a: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest): (self: HttpClient.With) => HttpClient.With; /** * Appends a transformation of the request object before sending it. * * @since 1.0.0 * @category mapping & sequencing */ (self: HttpClient.With, f: (a: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest): HttpClient.With; }; /** * Appends an effectful transformation of the request object before sending it. * * @since 1.0.0 * @category mapping & sequencing */ export declare const mapRequestEffect: { /** * Appends an effectful transformation of the request object before sending it. * * @since 1.0.0 * @category mapping & sequencing */ (f: (a: ClientRequest.HttpClientRequest) => Effect.Effect): (self: HttpClient.With) => HttpClient.With; /** * Appends an effectful transformation of the request object before sending it. * * @since 1.0.0 * @category mapping & sequencing */ (self: HttpClient.With, f: (a: ClientRequest.HttpClientRequest) => Effect.Effect): HttpClient.With; }; /** * Prepends a transformation of the request object before sending it. * * @since 1.0.0 * @category mapping & sequencing */ export declare const mapRequestInput: { /** * Prepends a transformation of the request object before sending it. * * @since 1.0.0 * @category mapping & sequencing */ (f: (a: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest): (self: HttpClient.With) => HttpClient.With; /** * Prepends a transformation of the request object before sending it. * * @since 1.0.0 * @category mapping & sequencing */ (self: HttpClient.With, f: (a: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest): HttpClient.With; }; /** * Prepends an effectful transformation of the request object before sending it. * * @since 1.0.0 * @category mapping & sequencing */ export declare const mapRequestInputEffect: { /** * Prepends an effectful transformation of the request object before sending it. * * @since 1.0.0 * @category mapping & sequencing */ (f: (a: ClientRequest.HttpClientRequest) => Effect.Effect): (self: HttpClient.With) => HttpClient.With; /** * Prepends an effectful transformation of the request object before sending it. * * @since 1.0.0 * @category mapping & sequencing */ (self: HttpClient.With, f: (a: ClientRequest.HttpClientRequest) => Effect.Effect): HttpClient.With; }; /** * @since 1.0.0 * @category error handling */ export declare namespace Retry { /** * @since 1.0.0 * @category error handling */ type Return, O>> = HttpClient.With<(O extends { schedule: Schedule.Schedule; } ? E : O extends { until: Predicate.Refinement; } ? E2 : E) | (O extends { while: (...args: Array) => Effect.Effect; } ? E : never) | (O extends { until: (...args: Array) => Effect.Effect; } ? E : never), R | (O extends { schedule: Schedule.Schedule; } ? R : never) | (O extends { while: (...args: Array) => Effect.Effect; } ? R : never) | (O extends { until: (...args: Array) => Effect.Effect; } ? R : never)> extends infer Z ? Z : never; } /** * Retries the request based on a provided schedule or policy. * * @since 1.0.0 * @category error handling */ export declare const retry: { /** * Retries the request based on a provided schedule or policy. * * @since 1.0.0 * @category error handling */ , O>>(options: O): (self: HttpClient.With) => Retry.Return; /** * Retries the request based on a provided schedule or policy. * * @since 1.0.0 * @category error handling */ (policy: Schedule.Schedule, R1>): (self: HttpClient.With) => HttpClient.With; /** * Retries the request based on a provided schedule or policy. * * @since 1.0.0 * @category error handling */ , O>>(self: HttpClient.With, options: O): Retry.Return; /** * Retries the request based on a provided schedule or policy. * * @since 1.0.0 * @category error handling */ (self: HttpClient.With, policy: Schedule.Schedule): HttpClient.With; }; /** * Retries common transient errors, such as rate limiting, timeouts or network issues. * * Specifying a `while` predicate allows you to consider other errors as * transient. * * @since 1.0.0 * @category error handling */ export declare const retryTransient: { /** * Retries common transient errors, such as rate limiting, timeouts or network issues. * * Specifying a `while` predicate allows you to consider other errors as * transient. * * @since 1.0.0 * @category error handling */ (options: { readonly mode?: Mode | undefined; readonly while?: Predicate.Predicate>; readonly schedule?: Schedule.Schedule, R1>; readonly times?: number; } | Schedule.Schedule, R1>): (self: HttpClient.With) => HttpClient.With; /** * Retries common transient errors, such as rate limiting, timeouts or network issues. * * Specifying a `while` predicate allows you to consider other errors as * transient. * * @since 1.0.0 * @category error handling */ (self: HttpClient.With, options: { readonly mode?: Mode | undefined; readonly while?: Predicate.Predicate>; readonly schedule?: Schedule.Schedule, R1>; readonly times?: number; } | Schedule.Schedule, R1>): HttpClient.With; }; /** * Performs an additional effect after a successful request. * * @since 1.0.0 * @category mapping & sequencing */ export declare const tap: { /** * Performs an additional effect after a successful request. * * @since 1.0.0 * @category mapping & sequencing */ <_, E2, R2>(f: (response: ClientResponse.HttpClientResponse) => Effect.Effect<_, E2, R2>): (self: HttpClient.With) => HttpClient.With; /** * Performs an additional effect after a successful request. * * @since 1.0.0 * @category mapping & sequencing */ (self: HttpClient.With, f: (response: ClientResponse.HttpClientResponse) => Effect.Effect<_, E2, R2>): HttpClient.With; }; /** * Performs an additional effect after an unsuccessful request. * * @since 1.0.0 * @category mapping & sequencing */ export declare const tapError: { /** * Performs an additional effect after an unsuccessful request. * * @since 1.0.0 * @category mapping & sequencing */ <_, E, E2, R2>(f: (e: NoInfer) => Effect.Effect<_, E2, R2>): (self: HttpClient.With) => HttpClient.With; /** * Performs an additional effect after an unsuccessful request. * * @since 1.0.0 * @category mapping & sequencing */ (self: HttpClient.With, f: (e: NoInfer) => Effect.Effect<_, E2, R2>): HttpClient.With; }; /** * Performs an additional effect on the request before sending it. * * @since 1.0.0 * @category mapping & sequencing */ export declare const tapRequest: { /** * Performs an additional effect on the request before sending it. * * @since 1.0.0 * @category mapping & sequencing */ <_, E2, R2>(f: (a: ClientRequest.HttpClientRequest) => Effect.Effect<_, E2, R2>): (self: HttpClient.With) => HttpClient.With; /** * Performs an additional effect on the request before sending it. * * @since 1.0.0 * @category mapping & sequencing */ (self: HttpClient.With, f: (a: ClientRequest.HttpClientRequest) => Effect.Effect<_, E2, R2>): HttpClient.With; }; /** * Associates a `Ref` of cookies with the client for handling cookies across requests. * * @since 1.0.0 * @category cookies */ export declare const withCookiesRef: { /** * Associates a `Ref` of cookies with the client for handling cookies across requests. * * @since 1.0.0 * @category cookies */ (ref: Ref): (self: HttpClient.With) => HttpClient.With; /** * Associates a `Ref` of cookies with the client for handling cookies across requests. * * @since 1.0.0 * @category cookies */ (self: HttpClient.With, ref: Ref): HttpClient.With; }; /** * Follows HTTP redirects up to a specified number of times. * * @since 1.0.0 * @category redirects */ export declare const followRedirects: { /** * Follows HTTP redirects up to a specified number of times. * * @since 1.0.0 * @category redirects */ (maxRedirects?: number | undefined): (self: HttpClient.With) => HttpClient.With; /** * Follows HTTP redirects up to a specified number of times. * * @since 1.0.0 * @category redirects */ (self: HttpClient.With, maxRedirects?: number | undefined): HttpClient.With; }; /** * @since 1.0.0 * @category Tracing */ export declare const currentTracerDisabledWhen: FiberRef.FiberRef>; /** * Disables tracing for specific requests based on a provided predicate. * * @since 1.0.0 * @category Tracing */ export declare const withTracerDisabledWhen: { /** * Disables tracing for specific requests based on a provided predicate. * * @since 1.0.0 * @category Tracing */ (predicate: Predicate.Predicate): (self: HttpClient.With) => HttpClient.With; /** * Disables tracing for specific requests based on a provided predicate. * * @since 1.0.0 * @category Tracing */ (self: HttpClient.With, predicate: Predicate.Predicate): HttpClient.With; }; /** * @since 1.0.0 * @category Tracing */ export declare const currentTracerPropagation: FiberRef.FiberRef; /** * Enables or disables tracing propagation for the request. * * @since 1.0.0 * @category Tracing */ export declare const withTracerPropagation: { /** * Enables or disables tracing propagation for the request. * * @since 1.0.0 * @category Tracing */ (enabled: boolean): (self: HttpClient.With) => HttpClient.With; /** * Enables or disables tracing propagation for the request. * * @since 1.0.0 * @category Tracing */ (self: HttpClient.With, enabled: boolean): HttpClient.With; }; /** * @since 1.0.0 */ export declare const layerMergedContext: (effect: Effect.Effect) => Layer; /** * @since 1.0.0 * @category Tracing */ export interface SpanNameGenerator { readonly _: unique symbol; } /** * @since 1.0.0 * @category Tracing */ export declare const SpanNameGenerator: Context.Reference string>; /** * Customizes the span names for tracing. * * ```ts * import { FetchHttpClient, HttpClient } from "@effect/platform" * import { NodeRuntime } from "@effect/platform-node" * import { Effect } from "effect" * * Effect.gen(function* () { * const client = (yield* HttpClient.HttpClient).pipe( * // Customize the span names for this HttpClient * HttpClient.withSpanNameGenerator( * (request) => `http.client ${request.method} ${request.url}` * ) * ) * * yield* client.get("https://jsonplaceholder.typicode.com/posts/1") * }).pipe(Effect.provide(FetchHttpClient.layer), NodeRuntime.runMain) * ``` * * @since 1.0.0 * @category Tracing */ export declare const withSpanNameGenerator: { /** * Customizes the span names for tracing. * * ```ts * import { FetchHttpClient, HttpClient } from "@effect/platform" * import { NodeRuntime } from "@effect/platform-node" * import { Effect } from "effect" * * Effect.gen(function* () { * const client = (yield* HttpClient.HttpClient).pipe( * // Customize the span names for this HttpClient * HttpClient.withSpanNameGenerator( * (request) => `http.client ${request.method} ${request.url}` * ) * ) * * yield* client.get("https://jsonplaceholder.typicode.com/posts/1") * }).pipe(Effect.provide(FetchHttpClient.layer), NodeRuntime.runMain) * ``` * * @since 1.0.0 * @category Tracing */ (f: (request: ClientRequest.HttpClientRequest) => string): (self: HttpClient.With) => HttpClient.With; /** * Customizes the span names for tracing. * * ```ts * import { FetchHttpClient, HttpClient } from "@effect/platform" * import { NodeRuntime } from "@effect/platform-node" * import { Effect } from "effect" * * Effect.gen(function* () { * const client = (yield* HttpClient.HttpClient).pipe( * // Customize the span names for this HttpClient * HttpClient.withSpanNameGenerator( * (request) => `http.client ${request.method} ${request.url}` * ) * ) * * yield* client.get("https://jsonplaceholder.typicode.com/posts/1") * }).pipe(Effect.provide(FetchHttpClient.layer), NodeRuntime.runMain) * ``` * * @since 1.0.0 * @category Tracing */ (self: HttpClient.With, f: (request: ClientRequest.HttpClientRequest) => string): HttpClient.With; }; /** * Ties the lifetime of the `HttpClientRequest` to a `Scope`. * * @since 1.0.0 * @category Scope */ export declare const withScope: (self: HttpClient.With) => HttpClient.With; //# sourceMappingURL=HttpClient.d.ts.map