Skip to content

HttpApiEndpoint

14 exports Added in v1.0.0 Source

Constructors

del

Added in v1.0.0 Source

Signature

declare const del: {
  <Name extends string>(name: Name): Constructor<Name, "DELETE">;
  <Name extends string>(name: Name, path: `/${string}`): HttpApiEndpoint<Name, "DELETE">;
};

get

Added in v1.0.0 Source

Signature

declare const get: {
  <Name extends string>(name: Name): Constructor<Name, "GET">;
  <Name extends string>(name: Name, path: `/${string}`): HttpApiEndpoint<Name, "GET">;
};

make

Added in v1.0.0 Source

Signature

declare function make<Method extends HttpMethod>(
  method: Method,
): {
  <Name extends string>(name: Name): Constructor<Name, Method>;
  <Name extends string>(name: Name, path: `/${string}`): HttpApiEndpoint<Name, Method>;
};

options

Added in v1.0.0 Source

Signature

declare const options: {
  <Name extends string>(name: Name): Constructor<Name, "OPTIONS">;
  <Name extends string>(name: Name, path: `/${string}`): HttpApiEndpoint<Name, "OPTIONS">;
};

patch

Added in v1.0.0 Source

Signature

declare const patch: {
  <Name extends string>(name: Name): Constructor<Name, "PATCH">;
  <Name extends string>(name: Name, path: `/${string}`): HttpApiEndpoint<Name, "PATCH">;
};

post

Added in v1.0.0 Source

Signature

declare const post: {
  <Name extends string>(name: Name): Constructor<Name, "POST">;
  <Name extends string>(name: Name, path: `/${string}`): HttpApiEndpoint<Name, "POST">;
};

put

Added in v1.0.0 Source

Signature

declare const put: {
  <Name extends string>(name: Name): Constructor<Name, "PUT">;
  <Name extends string>(name: Name, path: `/${string}`): HttpApiEndpoint<Name, "PUT">;
};

Guards

Signature

declare function isHttpApiEndpoint(
  u: unknown,
): u is HttpApiEndpoint<any, any, any, never, never, never, void, never, never, never>;

Models

HttpApiEndpoint interface

Added in v1.0.0 Source

Represents an API endpoint. An API endpoint is mapped to a single route on the underlying HttpRouter.

Signature

interface HttpApiEndpoint<
  out Name extends string,
  out Method extends HttpMethod,
  in out Path = never,
  in out UrlParams = never,
  in out Payload = never,
  in out Headers = never,
  in out Success = void,
  in out Error = never,
  out R = never,
  out RE = never,
> extends Pipeable {
  readonly [TypeId]: typeof TypeId;
  readonly annotations: Context<never>;
  readonly errorSchema: any;
  readonly headersSchema: Option<any>;
  readonly method: Method;
  readonly middlewares: ReadonlySet<TagClassAny>;
  readonly name: Name;
  readonly path: `/${string}`;
  readonly pathSchema: Option<any>;
  readonly payloadSchema: Option<any>;
  readonly successSchema: any;
  readonly urlParamsSchema: Option<any>;
  addError<E extends Any>(
    schema: E,
    annotations?: {
      readonly status?: number;
    },
  ): HttpApiEndpoint<
    Name,
    Method,
    Path,
    UrlParams,
    Payload,
    Headers,
    Success,
    Error | Type<E>,
    R,
    any
  >;
  addSuccess<S extends Any>(
    schema: S,
    annotations?: {
      readonly status?: number;
    },
  ): HttpApiEndpoint<
    Name,
    Method,
    Path,
    UrlParams,
    Payload,
    Headers,
    Exclude<Success, void> | Type<S>,
    Error,
    any,
    RE
  >;
  annotate<I, S>(
    tag: Tag<I, S>,
    value: S,
  ): HttpApiEndpoint<Name, Method, Path, UrlParams, Payload, Headers, Success, Error, R, RE>;
  annotateContext<I>(
    context: Context<I>,
  ): HttpApiEndpoint<Name, Method, Path, UrlParams, Payload, Headers, Success, Error, R, RE>;
  middleware<I extends AnyId, S>(
    middleware: Tag<I, S>,
  ): HttpApiEndpoint<
    Name,
    Method,
    Path,
    UrlParams,
    Payload,
    Headers,
    Success,
    Error | Error<I>,
    R | I,
    RE | ErrorContext<I>
  >;
  prefix(
    prefix: `/${string}`,
  ): HttpApiEndpoint<Name, Method, Path, UrlParams, Payload, Headers, Success, Error, R, RE>;
  setHeaders<H extends Any>(
    schema: any,
  ): HttpApiEndpoint<Name, Method, Path, UrlParams, Payload, Type<H>, Success, Error, any, RE>;
  setPath<Path extends Any>(
    schema: any,
  ): HttpApiEndpoint<
    Name,
    Method,
    Type<Path>,
    UrlParams,
    Payload,
    Headers,
    Success,
    Error,
    any,
    RE
  >;
  setPayload<P extends Any>(
    schema: P & ValidatePayload<Method, P>,
  ): HttpApiEndpoint<Name, Method, Path, UrlParams, Type<P>, Headers, Success, Error, any, RE>;
  setUrlParams<UrlParams extends Any>(
    schema: any,
  ): HttpApiEndpoint<
    Name,
    Method,
    Path,
    Type<UrlParams>,
    Payload,
    Headers,
    Success,
    Error,
    any,
    RE
  >;
}

PathSegment type

Added in v1.0.0 Source

Represents a path segment. A path segment is a string that represents a segment of a URL path.

Signature

type PathSegment = `/${string}`;

Type Ids

TypeId

Added in v1.0.0 Source

Signature

declare const TypeId: unique symbol;

TypeId type

Added in v1.0.0 Source

Signature

type TypeId = typeof TypeId;