Skip to main content Link Search Menu Expand Document (external link)

HttpClient overview

Added in v1.0.0


Table of contents


accessors

del

Signature

export declare const del: (
  url: string | URL,
  options?: ClientRequest.Options.NoUrl | undefined
) => Effect.Effect<ClientResponse.HttpClientResponse, Error.HttpClientError, Scope.Scope | HttpClient>

Added in v1.0.0

execute

Signature

export declare const execute: (
  request: ClientRequest.HttpClientRequest
) => Effect.Effect<ClientResponse.HttpClientResponse, Error.HttpClientError, Scope.Scope | HttpClient>

Added in v1.0.0

get

Signature

export declare const get: (
  url: string | URL,
  options?: ClientRequest.Options.NoBody | undefined
) => Effect.Effect<ClientResponse.HttpClientResponse, Error.HttpClientError, Scope.Scope | HttpClient>

Added in v1.0.0

Signature

export declare const head: (
  url: string | URL,
  options?: ClientRequest.Options.NoBody | undefined
) => Effect.Effect<ClientResponse.HttpClientResponse, Error.HttpClientError, Scope.Scope | HttpClient>

Added in v1.0.0

options

Signature

export declare const options: (
  url: string | URL,
  options?: ClientRequest.Options.NoUrl | undefined
) => Effect.Effect<ClientResponse.HttpClientResponse, Error.HttpClientError, Scope.Scope | HttpClient>

Added in v1.0.0

patch

Signature

export declare const patch: (
  url: string | URL,
  options?: ClientRequest.Options.NoUrl | undefined
) => Effect.Effect<ClientResponse.HttpClientResponse, Error.HttpClientError, Scope.Scope | HttpClient>

Added in v1.0.0

post

Signature

export declare const post: (
  url: string | URL,
  options?: ClientRequest.Options.NoUrl | undefined
) => Effect.Effect<ClientResponse.HttpClientResponse, Error.HttpClientError, Scope.Scope | HttpClient>

Added in v1.0.0

put

Signature

export declare const put: (
  url: string | URL,
  options?: ClientRequest.Options.NoUrl | undefined
) => Effect.Effect<ClientResponse.HttpClientResponse, Error.HttpClientError, Scope.Scope | HttpClient>

Added in v1.0.0

constructors

make

Signature

export declare const make: (
  f: (
    request: ClientRequest.HttpClientRequest,
    url: URL,
    signal: AbortSignal,
    fiber: RuntimeFiber<ClientResponse.HttpClientResponse, Error.HttpClientError>
  ) => Effect.Effect<ClientResponse.HttpClientResponse, Error.HttpClientError, Scope.Scope>
) => HttpClient

Added in v1.0.0

makeWith

Signature

export declare const makeWith: <E2, R2, E, R>(
  postprocess: (
    request: Effect.Effect<ClientRequest.HttpClientRequest, E2, R2>
  ) => Effect.Effect<ClientResponse.HttpClientResponse, E, R>,
  preprocess: HttpClient.Preprocess<E2, R2>
) => HttpClient<E, R>

Added in v1.0.0

cookies

withCookiesRef

Associates a Ref of cookies with the client for handling cookies across requests.

Signature

export declare const withCookiesRef: {
  (ref: Ref<Cookies>): <E, R>(self: HttpClient<E, R>) => HttpClient<E, R>
  <E, R>(self: HttpClient<E, R>, ref: Ref<Cookies>): HttpClient<E, R>
}

Added in v1.0.0

error handling

Retry (namespace)

Added in v1.0.0

Return (type alias)

Signature

export type Return<R, E, O extends Effect.Retry.Options<E>> =
  HttpClient<
    | (O extends { schedule: Schedule.Schedule<infer _O, infer _I, infer _R> }
        ? E
        : O extends { until: Predicate.Refinement<E, infer E2> }
          ? E2
          : E)
    | (O extends { while: (...args: Array<any>) => Effect.Effect<infer _A, infer E, infer _R> } ? E : never)
    | (O extends { until: (...args: Array<any>) => Effect.Effect<infer _A, infer E, infer _R> } ? E : never),
    | R
    | (O extends { schedule: Schedule.Schedule<infer _O, infer _I, infer R> } ? R : never)
    | (O extends { while: (...args: Array<any>) => Effect.Effect<infer _A, infer _E, infer R> } ? R : never)
    | (O extends { until: (...args: Array<any>) => Effect.Effect<infer _A, infer _E, infer R> } ? R : never)
  > extends infer Z
    ? Z
    : never

Added in v1.0.0

catchAll

Signature

export declare const catchAll: {
  <E, E2, R2>(
    f: (e: E) => Effect.Effect<ClientResponse.HttpClientResponse, E2, R2>
  ): <R>(self: HttpClient<E, R>) => HttpClient<E2, R2 | R>
  <E, R, A2, E2, R2>(self: HttpClient<E, R>, f: (e: E) => Effect.Effect<A2, E2, R2>): HttpClient<E2, R | R2>
}

Added in v1.0.0

catchTag

Signature

export declare const catchTag: {
  <K extends E extends { _tag: string } ? E["_tag"] : never, E, E1, R1>(
    tag: K,
    f: (e: Extract<E, { _tag: K }>) => Effect.Effect<ClientResponse.HttpClientResponse, E1, R1>
  ): <R>(self: HttpClient<E, R>) => HttpClient<E1 | Exclude<E, { _tag: K }>, R1 | R>
  <R, E, K extends E extends { _tag: string } ? E["_tag"] : never, R1, E1>(
    self: HttpClient<E, R>,
    tag: K,
    f: (e: Extract<E, { _tag: K }>) => Effect.Effect<ClientResponse.HttpClientResponse, E1, R1>
  ): HttpClient<E1 | Exclude<E, { _tag: K }>, R1 | R>
}

Added in v1.0.0

catchTags

Signature

export declare const catchTags: {
  <
    E,
    Cases extends {
      [K in Extract<E, { _tag: string }>["_tag"]]+?: (
        error: Extract<E, { _tag: K }>
      ) => Effect.Effect<ClientResponse.HttpClientResponse, any, any>
    } & (unknown extends E ? {} : { [K in Exclude<keyof Cases, Extract<E, { _tag: string }>["_tag"]>]: never })
  >(
    cases: Cases
  ): <R>(
    self: HttpClient<E, R>
  ) => HttpClient<
    | Exclude<E, { _tag: keyof Cases }>
    | {
        [K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, infer E, any> ? E : never
      }[keyof Cases],
    | R
    | {
        [K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, any, infer R> ? R : never
      }[keyof Cases]
  >
  <
    E extends { _tag: string },
    R,
    Cases extends {
      [K in Extract<E, { _tag: string }>["_tag"]]+?: (
        error: Extract<E, { _tag: K }>
      ) => Effect.Effect<ClientResponse.HttpClientResponse, any, any>
    } & (unknown extends E ? {} : { [K in Exclude<keyof Cases, Extract<E, { _tag: string }>["_tag"]>]: never })
  >(
    self: HttpClient<E, R>,
    cases: Cases
  ): HttpClient<
    | Exclude<E, { _tag: keyof Cases }>
    | {
        [K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, infer E, any> ? E : never
      }[keyof Cases],
    | R
    | {
        [K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, any, infer R> ? R : never
      }[keyof Cases]
  >
}

Added in v1.0.0

retry

Retries the request based on a provided schedule or policy.

Signature

export declare const retry: {
  <E, O extends Effect.Retry.Options<E>>(options: O): <R>(self: HttpClient<E, R>) => Retry.Return<R, E, O>
  <B, E, R1>(policy: Schedule.Schedule<B, NoInfer<E>, R1>): <R>(self: HttpClient<E, R>) => HttpClient<E, R1 | R>
  <E, R, O extends Effect.Retry.Options<E>>(self: HttpClient<E, R>, options: O): Retry.Return<R, E, O>
  <E, R, B, R1>(self: HttpClient<E, R>, policy: Schedule.Schedule<B, E, R1>): HttpClient<E, R1 | R>
}

Added in v1.0.0

retryTransient

Retries common transient errors, such as rate limiting or network issues.

Signature

export declare const retryTransient: {
  <B, E, R1 = never>(
    options:
      | { readonly schedule?: Schedule.Schedule<B, NoInfer<E>, R1>; readonly times?: number }
      | Schedule.Schedule<B, NoInfer<E>, R1>
  ): <R>(self: HttpClient<E, R>) => HttpClient<E, R1 | R>
  <E, R, B, R1 = never>(
    self: HttpClient<E, R>,
    options:
      | { readonly schedule?: Schedule.Schedule<B, NoInfer<E>, R1>; readonly times?: number }
      | Schedule.Schedule<B, NoInfer<E>, R1>
  ): HttpClient<E, R1 | R>
}

Added in v1.0.0

fiber refs

currentTracerDisabledWhen

Signature

export declare const currentTracerDisabledWhen: FiberRef.FiberRef<Predicate.Predicate<ClientRequest.HttpClientRequest>>

Added in v1.0.0

currentTracerPropagation

Signature

export declare const currentTracerPropagation: FiberRef.FiberRef<boolean>

Added in v1.0.0

withTracerDisabledWhen

Disables tracing for specific requests based on a provided predicate.

Signature

export declare const withTracerDisabledWhen: {
  (
    predicate: Predicate.Predicate<ClientRequest.HttpClientRequest>
  ): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
  <A, E, R>(
    effect: Effect.Effect<A, E, R>,
    predicate: Predicate.Predicate<ClientRequest.HttpClientRequest>
  ): Effect.Effect<A, E, R>
}

Added in v1.0.0

withTracerPropagation

Enables or disables tracing propagation for the request.

Signature

export declare const withTracerPropagation: {
  (enabled: boolean): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
  <A, E, R>(effect: Effect.Effect<A, E, R>, enabled: boolean): Effect.Effect<A, E, R>
}

Added in v1.0.0

filters

filterOrElse

Filters the result of a response, or runs an alternative effect if the predicate fails.

Signature

export declare const filterOrElse: {
  <E2, R2>(
    predicate: Predicate.Predicate<ClientResponse.HttpClientResponse>,
    orElse: (response: ClientResponse.HttpClientResponse) => Effect.Effect<ClientResponse.HttpClientResponse, E2, R2>
  ): <E, R>(self: HttpClient<E, R>) => HttpClient<E2 | E, R2 | R>
  <E, R, E2, R2>(
    self: HttpClient<E, R>,
    predicate: Predicate.Predicate<ClientResponse.HttpClientResponse>,
    orElse: (response: ClientResponse.HttpClientResponse) => Effect.Effect<ClientResponse.HttpClientResponse, E2, R2>
  ): HttpClient<E2 | E, R2 | R>
}

Added in v1.0.0

filterOrFail

Filters the result of a response, or throws an error if the predicate fails.

Signature

export declare const filterOrFail: {
  <E2>(
    predicate: Predicate.Predicate<ClientResponse.HttpClientResponse>,
    orFailWith: (response: ClientResponse.HttpClientResponse) => E2
  ): <E, R>(self: HttpClient<E, R>) => HttpClient<E2 | E, R>
  <E, R, E2>(
    self: HttpClient<E, R>,
    predicate: Predicate.Predicate<ClientResponse.HttpClientResponse>,
    orFailWith: (response: ClientResponse.HttpClientResponse) => E2
  ): HttpClient<E2 | E, R>
}

Added in v1.0.0

filterStatus

Filters responses by HTTP status code.

Signature

export declare const filterStatus: {
  (f: (status: number) => boolean): <E, R>(self: HttpClient<E, R>) => HttpClient<E | Error.ResponseError, R>
  <E, R>(self: HttpClient<E, R>, f: (status: number) => boolean): HttpClient<E | Error.ResponseError, R>
}

Added in v1.0.0

filterStatusOk

Filters responses that return a 2xx status code.

Signature

export declare const filterStatusOk: <E, R>(self: HttpClient<E, R>) => HttpClient<E | Error.ResponseError, R>

Added in v1.0.0

mapping & sequencing

mapRequest

Appends a transformation of the request object before sending it.

Signature

export declare const mapRequest: {
  (
    f: (a: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest
  ): <E, R>(self: HttpClient<E, R>) => HttpClient<E, R>
  <E, R>(
    self: HttpClient<E, R>,
    f: (a: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest
  ): HttpClient<E, R>
}

Added in v1.0.0

mapRequestEffect

Appends an effectful transformation of the request object before sending it.

Signature

export declare const mapRequestEffect: {
  <E2, R2>(
    f: (a: ClientRequest.HttpClientRequest) => Effect.Effect<ClientRequest.HttpClientRequest, E2, R2>
  ): <E, R>(self: HttpClient<E, R>) => HttpClient<E | E2, R | R2>
  <E, R, E2, R2>(
    self: HttpClient<E, R>,
    f: (a: ClientRequest.HttpClientRequest) => Effect.Effect<ClientRequest.HttpClientRequest, E2, R2>
  ): HttpClient<E | E2, R | R2>
}

Added in v1.0.0

mapRequestInput

Prepends a transformation of the request object before sending it.

Signature

export declare const mapRequestInput: {
  (
    f: (a: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest
  ): <E, R>(self: HttpClient<E, R>) => HttpClient<E, R>
  <E, R>(
    self: HttpClient<E, R>,
    f: (a: ClientRequest.HttpClientRequest) => ClientRequest.HttpClientRequest
  ): HttpClient<E, R>
}

Added in v1.0.0

mapRequestInputEffect

Prepends an effectful transformation of the request object before sending it.

Signature

export declare const mapRequestInputEffect: {
  <E2, R2>(
    f: (a: ClientRequest.HttpClientRequest) => Effect.Effect<ClientRequest.HttpClientRequest, E2, R2>
  ): <E, R>(self: HttpClient<E, R>) => HttpClient<E | E2, R | R2>
  <E, R, E2, R2>(
    self: HttpClient<E, R>,
    f: (a: ClientRequest.HttpClientRequest) => Effect.Effect<ClientRequest.HttpClientRequest, E2, R2>
  ): HttpClient<E | E2, R | R2>
}

Added in v1.0.0

tap

Performs an additional effect after a successful request.

Signature

export declare const tap: {
  <_, E2, R2>(
    f: (response: ClientResponse.HttpClientResponse) => Effect.Effect<_, E2, R2>
  ): <E, R>(self: HttpClient<E, R>) => HttpClient<E | E2, R | R2>
  <E, R, _, E2, R2>(
    self: HttpClient<E, R>,
    f: (response: ClientResponse.HttpClientResponse) => Effect.Effect<_, E2, R2>
  ): HttpClient<E | E2, R | R2>
}

Added in v1.0.0

tapRequest

Performs an additional effect on the request before sending it.

Signature

export declare const tapRequest: {
  <_, E2, R2>(
    f: (a: ClientRequest.HttpClientRequest) => Effect.Effect<_, E2, R2>
  ): <E, R>(self: HttpClient<E, R>) => HttpClient<E | E2, R | R2>
  <E, R, _, E2, R2>(
    self: HttpClient<E, R>,
    f: (a: ClientRequest.HttpClientRequest) => Effect.Effect<_, E2, R2>
  ): HttpClient<E | E2, R | R2>
}

Added in v1.0.0

transform

Signature

export declare const transform: {
  <E, R, E1, R1>(
    f: (
      effect: Effect.Effect<ClientResponse.HttpClientResponse, E, R>,
      request: ClientRequest.HttpClientRequest
    ) => Effect.Effect<ClientResponse.HttpClientResponse, E1, R1>
  ): (self: HttpClient<E, R>) => HttpClient<E | E1, R | R1>
  <E, R, E1, R1>(
    self: HttpClient<E, R>,
    f: (
      effect: Effect.Effect<ClientResponse.HttpClientResponse, E, R>,
      request: ClientRequest.HttpClientRequest
    ) => Effect.Effect<ClientResponse.HttpClientResponse, E1, R1>
  ): HttpClient<E | E1, R | R1>
}

Added in v1.0.0

transformResponse

Signature

export declare const transformResponse: {
  <E, R, E1, R1>(
    f: (
      effect: Effect.Effect<ClientResponse.HttpClientResponse, E, R>
    ) => Effect.Effect<ClientResponse.HttpClientResponse, E1, R1>
  ): (self: HttpClient<E, R>) => HttpClient<E1, R1>
  <E, R, E1, R1>(
    self: HttpClient<E, R>,
    f: (
      effect: Effect.Effect<ClientResponse.HttpClientResponse, E, R>
    ) => Effect.Effect<ClientResponse.HttpClientResponse, E1, R1>
  ): HttpClient<E1, R1>
}

Added in v1.0.0

models

HttpClient (interface)

Signature

export interface HttpClient<E = Error.HttpClientError, R = Scope.Scope> extends Pipeable, Inspectable {
  readonly [TypeId]: TypeId
  readonly execute: (request: ClientRequest.HttpClientRequest) => Effect.Effect<ClientResponse.HttpClientResponse, E, R>

  readonly get: (
    url: string | URL,
    options?: ClientRequest.Options.NoBody
  ) => Effect.Effect<ClientResponse.HttpClientResponse, E, R>
  readonly head: (
    url: string | URL,
    options?: ClientRequest.Options.NoBody
  ) => Effect.Effect<ClientResponse.HttpClientResponse, E, R>
  readonly post: (
    url: string | URL,
    options?: ClientRequest.Options.NoUrl
  ) => Effect.Effect<ClientResponse.HttpClientResponse, E, R>
  readonly patch: (
    url: string | URL,
    options?: ClientRequest.Options.NoUrl
  ) => Effect.Effect<ClientResponse.HttpClientResponse, E, R>
  readonly put: (
    url: string | URL,
    options?: ClientRequest.Options.NoUrl
  ) => Effect.Effect<ClientResponse.HttpClientResponse, E, R>
  readonly del: (
    url: string | URL,
    options?: ClientRequest.Options.NoUrl
  ) => Effect.Effect<ClientResponse.HttpClientResponse, E, R>
  readonly options: (
    url: string | URL,
    options?: ClientRequest.Options.NoUrl
  ) => Effect.Effect<ClientResponse.HttpClientResponse, E, R>
}

Added in v1.0.0

redirects

followRedirects

Follows HTTP redirects up to a specified number of times.

Signature

export declare const followRedirects: {
  (maxRedirects?: number | undefined): <E, R>(self: HttpClient<E, R>) => HttpClient<E, R>
  <E, R>(self: HttpClient<E, R>, maxRedirects?: number | undefined): HttpClient<E, R>
}

Added in v1.0.0

tags

HttpClient

Signature

export declare const HttpClient: Context.Tag<
  HttpClient<Error.HttpClientError, Scope.Scope>,
  HttpClient<Error.HttpClientError, Scope.Scope>
>

Added in v1.0.0

type ids

TypeId

Signature

export declare const TypeId: typeof TypeId

Added in v1.0.0

TypeId (type alias)

Signature

export type TypeId = typeof TypeId

Added in v1.0.0

utils

HttpClient (namespace)

Added in v1.0.0

Postprocess (type alias)

Signature

export type Postprocess<E = never, R = never> = (
  request: Effect.Effect<ClientRequest.HttpClientRequest, E, R>
) => Effect.Effect<ClientResponse.HttpClientResponse, E, R>

Added in v1.0.0

Preprocess (type alias)

Signature

export type Preprocess<E, R> = (
  request: ClientRequest.HttpClientRequest
) => Effect.Effect<ClientRequest.HttpClientRequest, E, R>

Added in v1.0.0

layerMergedContext

Signature

export declare const layerMergedContext: <E, R>(effect: Effect.Effect<HttpClient, E, R>) => Layer<HttpClient, E, R>

Added in v1.0.0