Skip to main content
Version: 0.24

Interface: Api

A custom HTTP endpoint mounted on the Wasp server.

Create one with the api constructor.

Unlike operations, APIs are plain Express handlers that receive req, res, and a Wasp context. They are useful for webhooks and any non-standard HTTP interaction.

See Custom HTTP API Endpoints.

Extendsโ€‹

  • BaseSpecElement<"api">

Propertiesโ€‹

auth?โ€‹

optional auth?: boolean

If true, the handler requires the request to come from an authenticated user and receives context.user. Defaults to true when the app has auth enabled, and false otherwise. Set to false to skip parsing the JWT from the Authorization header.


entities?โ€‹

optional entities?: string[]

Entities the handler operates on. Wasp injects a Prisma delegate for each one into the handler's context.entities.

See Using Entities in APIs.


fnโ€‹

fn: Reference<AnyFunction>

Reference to the API's NodeJS implementation.


kindโ€‹

kind: "api"

The internal Wasp type of a SpecElement. Used by the compiler. You should not set this field directly, instead use the dedicated constructors.

Inherited fromโ€‹

BaseSpecElement.kind


methodโ€‹

method: HttpMethod

HTTP method this endpoint responds to.


middlewareConfigFn?โ€‹

optional middlewareConfigFn?: Reference<AnyFunction>

Reference to an Express middleware config function for this endpoint only.

See Configuring API middleware.


pathโ€‹

path: string

Express path of the endpoint (e.g. "/webhooks/stripe").