Function: api()
api(
method,path,fn,config?):Api
Creates an Api endpoint definition.
APIs are custom HTTP endpoints handled by a plain Express function. Use them for webhooks, file uploads, or any HTTP interaction that doesn't fit the query/action model.
See Custom HTTP API Endpoints.
Parameters
method
HTTP method to listen on (or "ALL" for any).
path
string
Express path the endpoint is mounted at.
fn
Reference<AnyFunction>
The API's NodeJS implementation.
Use reference imports when passing values from your app into the Wasp spec. If a direct import is not practical, use ref as a fallback.
config?
Optional settings: middlewareConfigFn, entities, auth.
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?
string[]
Entities the handler operates on. Wasp injects a Prisma delegate for
each one into the handler's context.entities.
middlewareConfigFn?
Reference<AnyFunction>
Reference to an Express middleware config function for this endpoint only.
See Configuring API middleware.
Returns
Example
import { api } from '@wasp.sh/spec'
import { barBaz } from './src/apis' with { type: 'ref' }
api('GET', '/bar/baz', barBaz, { entities: ['Task'], auth: false })