Skip to main content
The RoutesOptions interface allows you to customize individual CRUD routes, exclude specific routes, or add decorators and interceptors to specific endpoints.

Interface Definition

export interface RoutesOptions {
  exclude?: BaseRouteName[];
  only?: BaseRouteName[];
  getManyBase?: GetManyRouteOptions;
  getOneBase?: GetOneRouteOptions;
  createOneBase?: CreateOneRouteOptions;
  createManyBase?: CreateManyRouteOptions;
  updateOneBase?: UpdateOneRouteOptions;
  replaceOneBase?: ReplaceOneRouteOptions;
  deleteOneBase?: DeleteOneRouteOptions;
  recoverOneBase?: RecoverOneRouteOptions;
}

Properties

exclude
BaseRouteName[]
Array of route names to exclude from the controller.Use this when you want most routes but need to exclude specific ones.
exclude: ['createManyBase', 'deleteOneBase']
only
BaseRouteName[]
Array of route names to include. Only these routes will be generated.Use this when you want only specific routes and want to exclude everything else.
only: ['getManyBase', 'getOneBase']
getManyBase
GetManyRouteOptions
Configuration for the GET (list) endpoint.Accepts BaseRouteOptions with interceptors and decorators properties.
getOneBase
GetOneRouteOptions
Configuration for the GET (single) endpoint.Accepts BaseRouteOptions with interceptors and decorators properties.
createOneBase
CreateOneRouteOptions
Configuration for the POST (create single) endpoint.Extends BaseRouteOptions with:
  • returnShallow: If true, returns only the created entity’s ID instead of the full entity
createManyBase
CreateManyRouteOptions
Configuration for the POST (create bulk) endpoint.Accepts BaseRouteOptions with interceptors and decorators properties.
updateOneBase
UpdateOneRouteOptions
Configuration for the PATCH (partial update) endpoint.Extends BaseRouteOptions with:
  • allowParamsOverride: If true, allows request body to override URL parameters
  • returnShallow: If true, returns only the entity’s ID instead of the full entity
replaceOneBase
ReplaceOneRouteOptions
Configuration for the PUT (full replace) endpoint.Extends BaseRouteOptions with:
  • allowParamsOverride: If true, allows request body to override URL parameters
  • returnShallow: If true, returns only the entity’s ID instead of the full entity
deleteOneBase
DeleteOneRouteOptions
Configuration for the DELETE endpoint.Extends BaseRouteOptions with:
  • returnDeleted: If true, returns the deleted entity in the response
recoverOneBase
RecoverOneRouteOptions
Configuration for the PATCH (recover soft-deleted) endpoint.Extends BaseRouteOptions with:
  • returnRecovered: If true, returns the recovered entity in the response

BaseRouteOptions

All route-specific options extend from BaseRouteOptions:
export interface BaseRouteOptions {
  interceptors?: any[];
  decorators?: (PropertyDecorator | MethodDecorator)[];
}
interceptors
any[]
Array of NestJS interceptors to apply to this specific route.
interceptors: [LoggingInterceptor, TransformInterceptor]
decorators
(PropertyDecorator | MethodDecorator)[]
Array of decorators to apply to this specific route method.
decorators: [UseGuards(AuthGuard), ApiOperation({ summary: 'Get all heroes' })]

BaseRouteName Type

The BaseRouteName type includes all available CRUD route names:
type BaseRouteName =
  | 'getManyBase'
  | 'getOneBase'
  | 'createOneBase'
  | 'createManyBase'
  | 'updateOneBase'
  | 'replaceOneBase'
  | 'deleteOneBase'
  | 'recoverOneBase';

Usage Examples

Exclude Specific Routes

@Crud({
  model: { type: Hero },
  routes: {
    exclude: ['createManyBase', 'deleteOneBase'],
  },
})
@Controller('heroes')
export class HeroesController {}

Only Include Specific Routes

@Crud({
  model: { type: Hero },
  routes: {
    only: ['getManyBase', 'getOneBase'],
  },
})
@Controller('heroes')
export class HeroesController {}

Add Decorators and Interceptors

import { UseGuards } from '@nestjs/common';
import { ApiOperation } from '@nestjs/swagger';
import { AuthGuard } from './auth.guard';
import { LoggingInterceptor } from './logging.interceptor';

@Crud({
  model: { type: Hero },
  routes: {
    getManyBase: {
      decorators: [
        UseGuards(AuthGuard),
        ApiOperation({ summary: 'Get all heroes' }),
      ],
      interceptors: [LoggingInterceptor],
    },
    createOneBase: {
      returnShallow: true,
      decorators: [UseGuards(AuthGuard)],
    },
  },
})
@Controller('heroes')
export class HeroesController {}

Configure Return Behavior

@Crud({
  model: { type: Hero },
  routes: {
    createOneBase: {
      returnShallow: true, // Returns only { id: 1 }
    },
    updateOneBase: {
      returnShallow: false, // Returns full entity
      allowParamsOverride: true,
    },
    deleteOneBase: {
      returnDeleted: true, // Returns the deleted entity
    },
  },
})
@Controller('heroes')
export class HeroesController {}

Notes

You cannot use both exclude and only at the same time. Use exclude when you want most routes, or only when you want to be explicit about which routes to include.
When using returnShallow: true, the response will only contain the entity’s primary key field(s). This is useful for reducing response size but may require additional requests to fetch full entity data.

Build docs developers (and LLMs) love