Decorator reference

Every decorator in Bustan 0.0.2.

@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, Interceptor and their @Use* decorators
  • Added @SetMetadata, @Head, @Options
  • Added scope and async factories on Provider
  • Added guards on @Module, and app-level guards / interceptors
  • Added Pydantic models as body parameters
  • Deprecated Body() — removed in 0.1.0