@Module(...)#
| Argument | Type | Default | Description |
|---|---|---|---|
imports |
list of modules | [] |
Modules whose exports become available |
controllers |
list of classes | [] |
Controllers this module owns |
providers |
list of classes or Provider |
[] |
Providers this module owns |
exports |
list | [] |
Providers visible to importing modules |
guards |
list of guards | [] |
Guards applied to every route in the module |
@Controller(prefix)#
@Injectable()#
Route decorators#
| Decorator | Method |
|---|---|
@Get(path) |
GET |
@Post(path) |
POST |
@Put(path) |
PUT |
@Patch(path) |
PATCH |
@Delete(path) |
DELETE |
@Head(path) |
HEAD |
@Options(path) |
OPTIONS |
Parameter helpers#
| Helper | Reads from | Notes |
|---|---|---|
Query(name) |
Query string | Accepts pipes=[...] |
Header(name) |
Request header | Accepts pipes=[...] |
Param(name) |
Path parameter | Accepts pipes=[...] |
Body() |
JSON body | Deprecated — declare a Pydantic model instead |
A parameter annotated with a Pydantic model is read from the request body and validated automatically.
Cross-cutting decorators#
| Decorator | Applies | Description |
|---|---|---|
@UseGuards(*guards) |
route or controller | Authorisation checks |
@UsePipes(*pipes) |
route or controller | Parameter transformation |
@UseInterceptors(*interceptors) |
route or controller | Wrap handler execution |
@SetMetadata(key, value) |
route or controller | Attach metadata readable from a guard |
Base classes#
| Class | Method to implement |
|---|---|
Guard |
async def can_activate(context) -> bool |
Pipe |
async def transform(value) -> Any |
Interceptor |
async def intercept(context, call_next) |
Provider(...)#
| Argument | Description |
|---|---|
provide |
The type this satisfies |
token |
String token, as an alternative to provide |
value |
A ready-made instance |
factory |
A callable, sync or async |
inject |
What to pass the factory |
scope |
singleton (default) or request |
Bustan(root_module, **options)#
| Option | Type | Default | Description |
|---|---|---|---|
guards |
list | [] |
Guards applied to every route |
interceptors |
list | [] |
Interceptors applied to every route |
on_startup |
list of callables | [] |
Run after the container is built |
on_shutdown |
list of callables | [] |
Run on shutdown |
Changes from 0.0.1#
- Added
Guard,Pipe,Interceptorand their@Use*decorators - Added
@SetMetadata,@Head,@Options - Added
scopeand async factories onProvider - Added
guardson@Module, and app-levelguards/interceptors - Added Pydantic models as body parameters
- Deprecated
Body()— removed in0.1.0