@nestjsx/crud) is a microframework for building full-featured RESTful APIs with minimal boilerplate. It provides a declarative approach to creating CRUD endpoints with powerful query capabilities, validation, and database integration.
Three-layer architecture
The framework follows a clean three-layer architecture that separates concerns and keeps your code maintainable:Controllers
Define API endpoints using the
@Crud() decoratorServices
Handle business logic and database operations
Requests
Parse and validate query parameters
Key features
Automatic endpoint generation
The@Crud() decorator automatically generates up to 8 RESTful endpoints:
GET /resource- Get many resources with filtering, pagination, and sortingGET /resource/:id- Get one resource by IDPOST /resource- Create one resourcePOST /resource/bulk- Create many resourcesPATCH /resource/:id- Update one resource (partial)PUT /resource/:id- Replace one resource (full)DELETE /resource/:id- Delete one resourcePATCH /resource/:id/recover- Recover soft-deleted resource
The
recoverOneBase endpoint is only available when softDelete: true is enabled in query options.Rich query capabilities
Clients can use powerful query parameters to control responses:Built-in validation
The framework integrates withclass-validator and class-transformer to validate incoming data using validation groups:
Database agnostic
While@nestjsx/crud-typeorm provides TypeORM integration, the core framework is database agnostic. You can extend the base CrudService class to work with any database or ORM.
Packages
The framework consists of three main packages:@nestjsx/crud
Core package with decorators, interfaces, and route generation
@nestjsx/crud-typeorm
TypeORM integration with
TypeOrmCrudService@nestjsx/crud-request
Request parsing and query building utilities
Quick example
Here’s a minimal example showing all three layers:Next steps
Controllers
Learn how to configure CRUD controllers
Services
Understand CRUD services and database operations
Requests
Master query parameters and filtering
Quick start
Get started with a complete example