Libraries
    Preparing search index...

    Class EndpointBuilder<TParams, TBody, TQuery, THeaders, TServices, TPrincipal, TRoles, TResponse, TResponses, TUpload>

    Type Parameters

    • TParams = {}
    • TBody = undefined
    • TQuery = {}
    • THeaders = {}
    • TServices = {}
    • TPrincipal = undefined
    • TRoles extends string = string
    • TResponse = any
    • TResponses extends Record<number, any> = {}
    • TUpload extends boolean = false
    Index

    Constructors

    • Type Parameters

      • TParams = {}
      • TBody = undefined
      • TQuery = {}
      • THeaders = {}
      • TServices = {}
      • TPrincipal = undefined
      • TRoles extends string = string
      • TResponse = any
      • TResponses extends Record<number, any> = {}
      • TUpload extends boolean = false

      Parameters

      • method: string
      • basePath: string
      • pathTemplate: RoutePath
      • bodySchema: SchemaBuilder<any, any, any, any, any> | null
      • querySchema: ObjectSchemaBuilder<any, any, any, any, any, any, any> | null
      • headerSchema: ObjectSchemaBuilder<any, any, any, any, any, any, any> | null
      • serviceSchemas: Record<string, SchemaBuilder<any, any, any, any, any>> | null = null
      • authRoles: readonly string[] | null = null
      • summary: string | null = null
      • description: string | null = null
      • tags: readonly string[] = []
      • operationId: string | null = null
      • deprecated: boolean = false
      • responseSchema: SchemaBuilder<any, any, any, any, any> | null = null
      • responsesSchemas: Record<number, SchemaBuilder<any, any, any, any, any> | null> | null = null
      • example: unknown = null
      • examples:
            | Record<
                string,
                { description?: string; summary?: string; value: unknown },
            >
            | null = null
      • producesFile: { contentType?: string; description?: string } | null = null
      • produces: Record<string, { schema?: SchemaBuilder<any, any, any, any, any> }> | null = null
      • responseHeaderSchema: ObjectSchemaBuilder<any, any, any, any, any, any, any> | null = null
      • externalDocs: { description?: string; url: string } | null = null
      • links: Record<string, LinkDefinition<any>> | null = null
      • callbacks: Record<string, CallbackDefinition<any>> | null = null
      • fileUpload: UploadOptions | null = null
      • cacheTags: readonly CacheTagDefinition[] = []

      Returns EndpointBuilder<
          TParams,
          TBody,
          TQuery,
          THeaders,
          TServices,
          TPrincipal,
          TRoles,
          TResponse,
          TResponses,
          TUpload,
      >

    Accessors

    • get path(): string

      The full path for this endpoint, combining basePath and pathTemplate.

      For static routes this is the exact URL path (e.g. "/todos"). For dynamic routes the template placeholders are included (e.g. "/todos/:id").

      Returns string

    Methods

    • Declare that this endpoint can produce responses in multiple content types.

      Each key is a MIME type. Provide an optional schema to override the default response schema for that type; otherwise the schema from .returns() / .responses() is reused for every declared content type.

      When used alongside .producesFile(), the binary response takes precedence.

      Parameters

      • contentTypes: Record<string, { schema?: SchemaBuilder<any, any, any, any, any> }>

        Map of MIME type → optional schema override.

      Returns EndpointBuilder<
          TParams,
          TBody,
          TQuery,
          THeaders,
          TServices,
          TPrincipal,
          TRoles,
          TResponse,
          TResponses,
          TUpload,
      >

      endpoint.get('/api/items')
      .returns(object({ id: number(), name: string() }))
      .produces({
      'text/csv': {},
      'application/xml': { schema: string() }
      })
    • Declare per-status-code response schemas for OpenAPI generation and handler return-type enforcement.

      Pass null as the schema for body-less codes (e.g. 204).

      Type Parameters

      • const T extends Record<number, SchemaBuilder<any, any, any, any, any> | null>

      Parameters

      • map: T

      Returns EndpointBuilder<
          TParams,
          TBody,
          TQuery,
          THeaders,
          TServices,
          TPrincipal,
          TRoles,
          TResponse,
          InferResponsesMap<T>,
          TUpload,
      >

      const ep = endpoint
      .get('/api/todos/:id')
      .responses({
      200: object({ id: number(), title: string() }),
      404: object({ message: string() }),
      });

      const handler: Handler<typeof ep> = ({ params }) => {
      const todo = todos.get(params.id);
      if (!todo) return ActionResult.notFound({ message: 'Not found' });
      return todo; // plain object → 200
      };
    • Mark this endpoint as accepting multipart/form-data file uploads.

      When set, the server parses the request body with a streaming multipart parser instead of the default JSON deserializer. File fields are made available to the handler via arg.files (a Record<string, FilePart>), while non-file form fields are validated against the body schema and available via arg.body.

      Parameters

      • Optionaloptions: UploadOptions

        Upload configuration (max file size, allowed MIME types, etc.).

      Returns EndpointBuilder<
          TParams,
          TBody,
          TQuery,
          THeaders,
          TServices,
          TPrincipal,
          TRoles,
          TResponse,
          TResponses,
          true,
      >

      const UploadAvatar = endpoint
      .post('/api/avatar')
      .upload({ maxFileSize: 2 * 1024 * 1024, allowedMimeTypes: ['image/*'] })
      .authorize(PrincipalSchema)
      .responses({ 200: AvatarSchema });

      const handler: Handler<typeof UploadAvatar> = async ({ files }) => {
      const avatar = files['avatar'];
      // avatar: { filename, mimeType, buffer, size }
      };