The decorators module adds optional controller-style registration on top of Ingest's existing router APIs. It does not introduce automatic discovery, dependency injection, or a separate execution model.
import {
Controller,
Get,
On,
mount
} from '@stackpress/ingest/http';You can import the same decorators from:
@stackpress/ingest@stackpress/ingest/http@stackpress/ingest/whatwg
The decorators module exports:
ControllerAll,Connect,Delete,Get,Head,Options,Patch,Post,Put,TraceOnmount
Controller(basePath?) records a base path on a controller class. Route decorators mounted from that class use the base path as a prefix.
@Controller('/api')
class UserController {}Parameters
| Parameter | Type | Description |
|---|---|---|
basePath |
string |
Optional path prefix applied to route decorators on the class. Defaults to ''. |
Returns
A class decorator.
The route decorators register instance methods as router actions for a specific HTTP method.
import {
Controller,
Get,
Post,
type HttpAction
} from '@stackpress/ingest/http';
type HttpProps = Parameters<HttpAction>[0];
@Controller('/api')
class UserController {
@Get('/users')
public list({ res }: HttpProps) {
res.setJSON([{ id: 1 }]);
}
@Post('/users', 10)
public create({ res }: HttpProps) {
res.code = 201;
}
}Supported route decorators:
All(path, priority?)Connect(path, priority?)Delete(path, priority?)Get(path, priority?)Head(path, priority?)Options(path, priority?)Patch(path, priority?)Post(path, priority?)Put(path, priority?)Trace(path, priority?)
Parameters
| Parameter | Type | Description |
|---|---|---|
path |
string |
Route path segment for the decorated method. |
priority |
number |
Optional route priority. Higher numbers run first. Defaults to 0. |
Returns
A method decorator.
On(event, priority?) registers an instance method as a listener on the router event system.
import { On, type HttpAction } from '@stackpress/ingest/http';
type HttpProps = Parameters<HttpAction>[0];
class AuditController {
@On('GET /api/users', 10)
public log({ req, res }: HttpProps) {
res.headers.set('x-path', req.url.pathname);
}
}Parameters
| Parameter | Type | Description |
|---|---|---|
event |
string | RegExp |
Event name or event pattern to listen for. |
priority |
number |
Optional listener priority. Higher numbers run first. Defaults to 0. |
Returns
A method decorator.
mount(router, ...controllers) turns controller metadata into active routes and listeners on a Router or Server.
import {
Controller,
Get,
Router,
mount,
type HttpAction
} from '@stackpress/ingest/http';
type HttpProps = Parameters<HttpAction>[0];
@Controller('/api')
class UserController {
@Get('/users')
public list({ res }: HttpProps) {
res.setBody('text/plain', 'list');
}
}
const router = new Router();
mount(router, UserController);Parameters
| Parameter | Type | Description |
|---|---|---|
router |
Router<any, any, any, any> |
Router or Server instance that should receive the registrations. |
controllers |
ControllerMountable[] |
Controller classes or controller instances to mount. |
Returns
The same router instance for chaining.
- Decorators are optional. They only register existing
route()andon()calls for you. - Mounting is explicit. Ingest does not scan files or bootstrap controllers automatically.
ControllerMountableaccepts either a controller class or a controller instance.- Decorated methods should use explicit parameter types when destructuring props because decorators do not provide the same contextual typing as inline callbacks.
- Parameter decorators such as
@Body()or@Param()are not part of this feature. reflect-metadatais not required.