Skip to main content
The @Crud() decorator is the core feature of NestJS CRUD. It automatically generates RESTful API routes for your controller based on the configuration you provide.

Basic usage

Apply the @Crud() decorator to your controller class to generate CRUD routes:
This minimal configuration generates the following routes:
  • GET /users - Get many users
  • GET /users/:id - Get one user
  • POST /users - Create one user
  • POST /users/bulk - Create many users
  • PATCH /users/:id - Update one user
  • PUT /users/:id - Replace one user
  • DELETE /users/:id - Delete one user

Configuration options

The @Crud() decorator accepts a CrudOptions object with the following properties:
ModelOptions
required
The entity model for this controller. Must include a type property with your entity class.
DtoOptions
Custom DTOs for create, update, and replace operations.
SerializeOptions
Response serialization options for each route. Use DTOs to transform response data.
QueryOptions
Query configuration including filtering, sorting, pagination, and joins.See Query options for details.
RoutesOptions
Route-specific configuration to customize or exclude individual routes.See Route options for details.
ParamsOptions
URL parameter configuration for path parameters.See CRUD options for details.
ValidationPipeOptions | false
Validation pipe options or false to disable validation.See Validation for details.

Examples

With query configuration

With nested routes and params

With custom DTOs and serialization

With UUID primary key

Controller implementation

Your controller’s service must be exposed as a public property named service. The CRUD decorator uses this to access your service methods.

Minimal implementation

With CrudController interface

For better type safety, implement the CrudController interface:

Generated route names

The decorator generates these base route methods that you can override:
  • getManyBase - Get multiple entities
  • getOneBase - Get a single entity
  • createOneBase - Create a single entity
  • createManyBase - Create multiple entities (bulk)
  • updateOneBase - Update a single entity (partial)
  • replaceOneBase - Replace a single entity (full)
  • deleteOneBase - Delete a single entity
  • recoverOneBase - Recover a soft-deleted entity
See Overriding routes to learn how to customize these methods.

CRUD options

Detailed reference for all configuration options

Route options

Configure individual routes

Overriding routes

Customize generated route handlers

Validation

Configure request validation