Skip to main content
Version: Next

Function: apiNamespace()

apiNamespace(path, config): ApiNamespace

Creates an ApiNamespace definition.

Applies a shared middleware function to every api mounted under a given path prefix. Useful for tweaking middleware (e.g. raw body parsing, CORS) for a group of related endpoints.

See the per-path middleware section.

Parameters

path

string

Path prefix the namespace applies to.

config

Required middlewareConfigFn.

middlewareConfigFn

Reference<AnyFunction>

Reference to an Express middleware config function for this namespace.

Returns

ApiNamespace

Example

import { apiNamespace } from '@wasp.sh/spec'
import { barMiddleware } from './src/apis' with { type: 'ref' }

apiNamespace('/bar', { middlewareConfigFn: barMiddleware })