Creating a Controller
This is the shortest path from nothing to a working route. For the concepts behind each step, see Routing & Controllers.
1. Write the controller
Section titled “1. Write the controller”import { Controller, Get } from "@blixis-io/http";
@Controller("health")export class HealthController { @Get() check() { return { status: "ok" }; }}A controller with no constructor dependencies doesn’t even need @Injectable() — the container only reflects constructor parameters when there are any (see Dependency Injection). Once this controller needs a service, add one:
import { Controller, Get } from "@blixis-io/http";import { HealthService } from "./health.service.js";
@Controller("health")export class HealthController { constructor(private readonly health: HealthService) {}
@Get() check() { return this.health.status(); }}2. Register it on a module
Section titled “2. Register it on a module”import { Module } from "@blixis-io/core";import { HealthController } from "./health.controller.js";import { HealthService } from "./health.service.js";
@Module({ providers: [HealthService], controllers: [HealthController],})export class HealthModule {}A controller listed in controllers but missing @Controller() fails fast with NotAControllerError when the app builds — you’ll know immediately, not at request time.
3. Import the module into your app
Section titled “3. Import the module into your app”@Module({ imports: [HealthModule /* , ...your other modules */],})export class AppModule {}4. Add more routes
Section titled “4. Add more routes”@Get(":id")getOne(@Param("id") id: string) { /* ... */ }
@Post()create(@Body(CreateSchema) input: CreateInput) { /* ... */ }See Request Validation for @Body/@Query/@Param/@Headers, and Protecting Routes with Guards to add auth.