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

HttpApi overview

Added in v1.0.0


Table of contents


constructors

empty

An HttpApi is a collection of HttpApiEndpoints. You can use an HttpApi to represent a portion of your domain.

The endpoints can be implemented later using the HttpApiBuilder.make api.

Signature

export declare const empty: HttpApi<never, HttpApiDecodeError, never>

Added in v1.0.0

guards

isHttpApi

Signature

export declare const isHttpApi: (u: unknown) => u is HttpApi.Any

Added in v1.0.0

models

HttpApi (interface)

An HttpApi is a collection of HttpApiEndpoints. You can use an HttpApi to represent a portion of your domain.

The endpoints can be implemented later using the HttpApiBuilder.make api.

Signature

export interface HttpApi<out Groups extends HttpApiGroup.HttpApiGroup.Any = never, in out E = never, out R = never>
  extends Pipeable {
  new (_: never): {}
  readonly [TypeId]: TypeId
  readonly groups: Record.ReadonlyRecord<string, Groups>
  readonly annotations: Context.Context<never>
  readonly errorSchema: Schema.Schema<E, unknown, R>
  readonly middlewares: ReadonlySet<HttpApiMiddleware.TagClassAny>

  /**
   * Add a `HttpApiGroup` to the `HttpApi`.
   */
  add<A extends HttpApiGroup.HttpApiGroup.Any>(group: A): HttpApi<Groups | A, E, R>
  /**
   * Add another `HttpApi` to the `HttpApi`.
   */
  addHttpApi<Groups2 extends HttpApiGroup.HttpApiGroup.Any, E2, R2>(
    api: HttpApi<Groups2, E2, R2>
  ): HttpApi<Groups | HttpApiGroup.HttpApiGroup.AddContext<Groups2, R2>, E | E2, R>
  /**
   * Add an global error to the `HttpApi`.
   */
  addError<A, I, RX>(
    schema: Schema.Schema<A, I, RX>,
    annotations?: {
      readonly status?: number | undefined
    }
  ): HttpApi<Groups, E | A, R | RX>
  /**
   * Prefix all endpoints in the `HttpApi`.
   */
  prefix(prefix: PathInput): HttpApi<Groups, E, R>
  /**
   * Add a middleware to a `HttpApi`. It will be applied to all endpoints in the
   * `HttpApi`.
   */
  middleware<I extends HttpApiMiddleware.HttpApiMiddleware.AnyId, S>(
    middleware: Context.Tag<I, S>
  ): HttpApi<
    Groups,
    E | HttpApiMiddleware.HttpApiMiddleware.Error<I>,
    R | I | HttpApiMiddleware.HttpApiMiddleware.ErrorContext<I>
  >
  /**
   * Annotate the `HttpApi`.
   */
  annotate<I, S>(tag: Context.Tag<I, S>, value: S): HttpApi<Groups, E, R>
  /**
   * Annotate the `HttpApi` with a Context.
   */
  annotateContext<I>(context: Context.Context<I>): HttpApi<Groups, E, R>
}

Added in v1.0.0

HttpApi (namespace)

Added in v1.0.0

Any (interface)

Signature

export interface Any {
  readonly [TypeId]: TypeId
}

Added in v1.0.0

AnyWithProps (type alias)

Signature

export type AnyWithProps = HttpApi<HttpApiGroup.HttpApiGroup.AnyWithProps, any, any>

Added in v1.0.0

reflection

reflect

Extract metadata from an HttpApi, which can be used to generate documentation or other tooling.

See the OpenApi & HttpApiClient modules for examples of how to use this function.

Signature

export declare const reflect: <Groups extends HttpApiGroup.HttpApiGroup.Any, Error, R>(
  self: HttpApi<Groups, Error, R>,
  options: {
    readonly onGroup: (options: {
      readonly group: HttpApiGroup.HttpApiGroup.AnyWithProps
      readonly mergedAnnotations: Context.Context<never>
    }) => void
    readonly onEndpoint: (options: {
      readonly group: HttpApiGroup.HttpApiGroup.AnyWithProps
      readonly endpoint: HttpApiEndpoint.HttpApiEndpoint<string, HttpMethod>
      readonly mergedAnnotations: Context.Context<never>
      readonly middleware: ReadonlySet<HttpApiMiddleware.TagClassAny>
      readonly successes: ReadonlyMap<number, Option.Option<AST.AST>>
      readonly errors: ReadonlyMap<number, Option.Option<AST.AST>>
    }) => void
  }
) => void

Added in v1.0.0

tags

AdditionalSchemas (class)

Signature

export declare class AdditionalSchemas

Added in v1.0.0

Api (class)

Signature

export declare class Api

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