Cross-cutting concerns made easy. Use Interceptors, Guards, and Pipes to decouple logic from your business code.
Intercept/transform requests and responses.
Determine if a request should be handled.
Validate and transform input data.
Inspired by NestJS, interceptors allow you to wrap the execution stream. Perfect for logging, transformation, or caching.
1import { createInterceptor, UseInterceptors } from "canxjs";23// Define an Interceptor4const LoggingInterceptor = createInterceptor(async (context, next) => {5console.log('Before...');6const now = Date.now();78const result = await next();910console.log(`After... ${Date.now() - now}ms`);11return result;12});1314// Apply to Controller or Method15@UseInterceptors(LoggingInterceptor)16class CatsController {17// ...18}
1import { createGuard, UseGuards } from "canxjs";23const AuthGuard = createGuard((context) => {4const req = context.getRequest();5return validateRequest(req);6});78@UseGuards(AuthGuard)9class protectedController {}
1import { ParseIntPipe, UsePipes } from "canxjs";23@Post()4@UsePipes(ParseIntPipe) // Transforms params automatically5create(@Body() createCatDto: CreateCatDto) {6// ...7}