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

HttpApiClient overview

Added in v1.0.0


Table of contents


constructors

endpoint

Signature

export declare const endpoint: <
  ApiId extends string,
  Groups extends HttpApiGroup.Any,
  ApiError,
  ApiR,
  const GroupName extends HttpApiGroup.Name<Groups>,
  const EndpointName extends HttpApiEndpoint.Name<HttpApiGroup.EndpointsWithName<Groups, GroupName>>
>(
  api: HttpApi.HttpApi<ApiId, Groups, ApiError, ApiR>,
  groupName: GroupName,
  endpointName: EndpointName,
  options?: {
    readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
    readonly transformResponse?:
      | ((effect: Effect.Effect<unknown, unknown, Scope>) => Effect.Effect<unknown, unknown, Scope>)
      | undefined
    readonly baseUrl?: string | undefined
  }
) => Effect.Effect<
  Client.Method<
    HttpApiEndpoint.WithName<HttpApiGroup.Endpoints<HttpApiGroup.WithName<Groups, GroupName>>, EndpointName>,
    HttpApiGroup.Error<HttpApiGroup.WithName<Groups, GroupName>>,
    ApiError
  >,
  never,
  | HttpApiMiddleware.HttpApiMiddleware.Without<
      | ApiR
      | HttpApiGroup.Context<HttpApiGroup.WithName<Groups, GroupName>>
      | HttpApiEndpoint.ContextWithName<HttpApiGroup.EndpointsWithName<Groups, GroupName>, EndpointName>
      | HttpApiEndpoint.ErrorContextWithName<HttpApiGroup.EndpointsWithName<Groups, GroupName>, EndpointName>
    >
  | HttpClient.HttpClient
>

Added in v1.0.0

group

Signature

export declare const group: <
  ApiId extends string,
  Groups extends HttpApiGroup.Any,
  ApiError,
  ApiR,
  const GroupName extends Groups["identifier"]
>(
  api: HttpApi.HttpApi<ApiId, Groups, ApiError, ApiR>,
  groupId: GroupName,
  options?: {
    readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
    readonly transformResponse?:
      | ((effect: Effect.Effect<unknown, unknown, Scope>) => Effect.Effect<unknown, unknown, Scope>)
      | undefined
    readonly baseUrl?: string | undefined
  }
) => Effect.Effect<
  Client.Group<Groups, GroupName, ApiError>,
  never,
  | HttpApiMiddleware.HttpApiMiddleware.Without<
      ApiR | HttpApiGroup.ClientContext<HttpApiGroup.WithName<Groups, GroupName>>
    >
  | HttpClient.HttpClient
>

Added in v1.0.0

make

Signature

export declare const make: <ApiId extends string, Groups extends HttpApiGroup.Any, ApiError, ApiR>(
  api: HttpApi.HttpApi<ApiId, Groups, ApiError, ApiR>,
  options?: {
    readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined
    readonly transformResponse?:
      | ((effect: Effect.Effect<unknown, unknown, Scope>) => Effect.Effect<unknown, unknown, Scope>)
      | undefined
    readonly baseUrl?: string | undefined
  }
) => Effect.Effect<
  Simplify<Client<Groups, ApiError>>,
  never,
  HttpApiMiddleware.HttpApiMiddleware.Without<ApiR | HttpApiGroup.ClientContext<Groups>> | HttpClient.HttpClient
>

Added in v1.0.0

models

Client (type alias)

Signature

export type Client<Groups extends HttpApiGroup.Any, ApiError> = Simplify<
  {
    readonly [Group in Extract<Groups, { readonly topLevel: false }> as HttpApiGroup.Name<Group>]: Client.Group<
      Group,
      Group["identifier"],
      ApiError
    >
  } & {
    readonly [Method in Client.TopLevelMethods<Groups, ApiError> as Method[0]]: Method[1]
  }
>

Added in v1.0.0

Client (namespace)

Added in v1.0.0

Group (type alias)

Signature

export type Group<Groups extends HttpApiGroup.Any, GroupName extends Groups["identifier"], ApiError> = [
  HttpApiGroup.WithName<Groups, GroupName>
] extends [HttpApiGroup<infer _GroupName, infer _Endpoints, infer _GroupError, infer _GroupErrorR>]
  ? {
      readonly [Endpoint in _Endpoints as HttpApiEndpoint.Name<Endpoint>]: Method<Endpoint, ApiError, _GroupError>
    }
  : never

Added in v1.0.0

Method (type alias)

Signature

export type Method<Endpoint, ApiError, GroupError> = [Endpoint] extends [
  HttpApiEndpoint<
    infer _Name,
    infer _Method,
    infer _Path,
    infer _UrlParams,
    infer _Payload,
    infer _Headers,
    infer _Success,
    infer _Error,
    infer _R,
    infer _RE
  >
]
  ? <WithResponse extends boolean = false>(
      request: Simplify<HttpApiEndpoint.ClientRequest<_Path, _UrlParams, _Payload, _Headers, WithResponse>>
    ) => Effect.Effect<
      WithResponse extends true ? [_Success, HttpClientResponse.HttpClientResponse] : _Success,
      _Error | GroupError | ApiError | HttpClientError.HttpClientError
    >
  : never

Added in v1.0.0

TopLevelMethods (type alias)

Signature

export type TopLevelMethods<Groups extends HttpApiGroup.Any, ApiError> =
  Extract<Groups, { readonly topLevel: true }> extends HttpApiGroup<
    infer _Id,
    infer _Endpoints,
    infer _Error,
    infer _ErrorR,
    infer _TopLevel
  >
    ? _Endpoints extends infer Endpoint
      ? [HttpApiEndpoint.Name<Endpoint>, Method<Endpoint, ApiError, _Error>]
      : never
    : never

Added in v1.0.0