Skip to main content
CRUD controllers handle HTTP requests and delegate business logic to services. The @Crud() decorator automatically generates route handlers for common CRUD operations.

Basic controller

A minimal CRUD controller requires just three things:
  1. The @Crud() decorator with model configuration
  2. The @Controller() decorator with a route path
  3. A public service property
The service must be injected as a public property named service. This is required for the framework to automatically connect route handlers to service methods.

Configuration options

The @Crud() decorator accepts a configuration object with several options:

Model configuration

Define the entity model that the controller operates on:

Query options

Control which fields can be queried, filtered, and joined:
Use alwaysPaginate: true to force pagination on all list requests, which is recommended for production APIs with large datasets.

Route customization

Customize individual route behaviors:
From /home/daytona/workspace/source/integration/crud-typeorm/companies/companies.controller.ts:14-18:

Serialization

Control response serialization with DTOs:

Joins and relations

Configure how related entities are loaded and exposed:
From /home/daytona/workspace/source/integration/crud-typeorm/users/users.controller.ts:31-43:

Join options

  • alias - SQL alias for the joined table
  • allow - Fields that can be selected from the relation
  • exclude - Fields to hide from the relation
  • eager - Auto-load the relation on every request
  • select - Set to false to disable selecting fields (join only for filtering)
  • required - Use INNER JOIN instead of LEFT JOIN
  • persist - Fields always included in the response
Eager joins are loaded automatically even if not requested. Use sparingly to avoid performance issues.

Path parameters

Define route parameters for nested resources:
This creates routes like:
  • GET /companies/1/users - Get all users for company 1
  • GET /companies/1/users/5 - Get user 5 from company 1
  • POST /companies/1/users - Create user in company 1
From /home/daytona/workspace/source/integration/crud-typeorm/users/users.controller.ts:18-28:

Parameter options

  • field - Entity field to filter by
  • type - Parameter type ('number', 'uuid', 'string')
  • primary - Whether this is the primary key
  • disabled - Exclude from route generation

UUID parameters

For entities with UUID primary keys:
From /home/daytona/workspace/source/integration/crud-typeorm/devices/devices.controller.ts:12-18:

Overriding routes

Customize generated route handlers using the @Override() decorator:
From /home/daytona/workspace/source/integration/crud-typeorm/users/users.controller.ts:55-58:

Available route names

  • getManyBase - GET collection
  • getOneBase - GET single resource
  • createOneBase - POST single resource
  • createManyBase - POST bulk resources
  • updateOneBase - PATCH resource
  • replaceOneBase - PUT resource
  • deleteOneBase - DELETE resource
  • recoverOneBase - PATCH recover soft-deleted resource
Implement the CrudController<T> interface to get TypeScript autocomplete for route method names and signatures.

Swagger integration

The framework automatically generates Swagger/OpenAPI documentation. Enhance it with @ApiTags():
From /home/daytona/workspace/source/integration/crud-typeorm/companies/companies.controller.ts:45-49:

Complete example

Here’s a full-featured controller with all options:
From /home/daytona/workspace/source/integration/crud-typeorm/companies/companies.controller.ts:1-50:

Next steps

Services

Learn how to implement CRUD services

Requests

Understand request parsing and filtering