FastCrud is a lightweight, flexible CRUD API generator for .NET 9.
It combines Minimal APIs + EF Core + DTOs + FluentValidation + Gridify + Auto-Swagger to let you bootstrap production-ready endpoints with minimal effort.
Add the required FastCrud packages (version 0.2.1):
dotnet add package FastCrud.Abstractions -v 0.2.1
dotnet add package FastCrud.Core -v 0.2.1
dotnet add package FastCrud.Mapping.Mapster -v 0.2.1
dotnet add package FastCrud.PersistenceEfCore -v 0.2.1
dotnet add package FastCrud.Query.Gridify -v 0.2.1
dotnet add package FastCrud.Validation.FluentValidation -v 0.2.1
dotnet add package FastCrud.Web.MinimalApi -v 0.2.1Register FastCrud services:
builder.Services.AddFastCrudCore();
builder.Services.UseMapster();
builder.Services.UseGridifyQueryEngine();
builder.Services.UseFluentValidationAdapter();Register EF repositories per entity:
builder.Services.AddEfRepository<Customer, Guid, AppDbContext>();
builder.Services.AddEfRepository<Order, Guid, AppDbContext>();Define CRUD endpoints for each entity + DTO set:
app.MapFastCrud<Customer, Guid, CustomerCreateDto, CustomerUpdateDto, CustomerReadDto>(
"/api/customers",
nameof(Customer),
"v1"
);
app.MapFastCrud<Order, Guid, OrderCreateDto, OrderUpdateDto, OrderReadDto>(
"/api/orders",
nameof(Order),
"v1",
~CrudOps.Delete // disable Delete
);- Each entity requires 3 DTOs: CreateDto, UpdateDto, and ReadDto.
- By default, all CRUD operations are generated.
- To restrict operations, use the CrudOps flag with bitwise operators.
Add FluentValidation validators for your DTOs or entities:
public class CustomerValidator : AbstractValidator<Customer>
{
public CustomerValidator()
{
RuleFor(x => x.FirstName).NotEmpty().WithMessage("First name is required.");
RuleFor(x => x.LastName).NotEmpty();
RuleFor(x => x.Email).NotEmpty().EmailAddress();
}
}Validation is applied automatically to requests.
Enable advanced query options by writing a Gridify profile:
public sealed class CustomerGridifyProfile : IGridifyMapperProfile<Customer>
{
public void Configure(GridifyMapper<Customer> m)
{
m.Configuration.CaseInsensitiveFiltering = true;
m.GenerateMappings()
.AddMap("name", c => c.FirstName + " " + c.LastName)
.RemoveMap(nameof(Customer.CreatedUtc));
}
}This enables expressive queries like:
GET /api/customers?filter=name~"john"&sort=-CreatedUtc&page=1&pageSize=20
With just a few lines, you get:
- Clean Minimal APIs
- Automatic Swagger docs
- DTO mapping (Mapster)
- Validation (FluentValidation)
- Filtering, sorting & paging (Gridify)