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.
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.
middlewareConfigFnโ
Reference<AnyFunction>
Reference to an Express middleware config function for this namespace.
Returnsโ
Exampleโ
import { apiNamespace } from '@wasp.sh/spec'
import { barMiddleware } from './src/apis' with { type: 'ref' }
apiNamespace('/bar', { middlewareConfigFn: barMiddleware })