Prerequisites
Make sure you have completed the installation steps and have a NestJS project set up with TypeORM and NestJS CRUD installed.Create your first CRUD API
Create an entity
Create a TypeORM entity to define your data model. Add validation decorators from
class-validator:User.entity.ts
Create a service
Create a service that extends That’s it! The
TypeOrmCrudService to handle database operations:users.service.ts
TypeOrmCrudService provides all CRUD methods out of the box.Create a controller
Create a controller with the The
@Crud() decorator to automatically generate REST endpoints:users.controller.ts
@Crud() decorator automatically creates these endpoints:GET /users- Get all usersGET /users/:id- Get one userPOST /users- Create userPOST /users/bulk- Create multiple usersPATCH /users/:id- Update userPUT /users/:id- Replace userDELETE /users/:id- Delete user
Test your API
Start your NestJS application and test the auto-generated endpoints:Advanced querying
NestJS CRUD provides powerful query capabilities out of the box. Try these advanced queries:Filter operators
NestJS CRUD supports a wide range of filter operators:| Operator | Description | Example | ||||
|---|---|---|---|---|---|---|
$eq | Equals | `filter=name | eq | John` | ||
$ne | Not equals | `filter=name | ne | John` | ||
$gt | Greater than | `filter=age | gt | 18` | ||
$lt | Less than | `filter=age | lt | 65` | ||
$gte | Greater than or equal | `filter=age | gte | 21` | ||
$lte | Less than or equal | `filter=age | lte | 100` | ||
$starts | Starts with | `filter=name | starts | Jo` | ||
$ends | Ends with | `filter=email | ends | .com` | ||
$cont | Contains | `filter=name | cont | oh` | ||
$excl | Excludes | `filter=name | excl | test` | ||
$in | In array | `filter=id | in | 1,2,3` | ||
$notin | Not in array | `filter=id | notin | 4,5` | ||
$isnull | Is null | `filter=bio | isnull` | |||
$notnull | Is not null | `filter=bio | notnull` | |||
$between | Between values | `filter=age | between | 18,65` |
Configure query options
Customize the query behavior in your controller:users.controller.ts
Override endpoints
You can override any auto-generated endpoint to add custom logic:users.controller.ts
Next steps
Query parameters
Learn about all available query parameters and filtering options
Controllers
Understand CRUD controllers and configuration options
Services
Dive deeper into CRUD services and custom implementations
Advanced features
Explore authentication, serialization, and Swagger integration