DvBCrud.API
1.1.0
dotnet add package DvBCrud.API --version 1.1.0
NuGet\Install-Package DvBCrud.API -Version 1.1.0
<PackageReference Include="DvBCrud.API" Version="1.1.0" />
<PackageVersion Include="DvBCrud.API" Version="1.1.0" />
<PackageReference Include="DvBCrud.API" />
paket add DvBCrud.API --version 1.1.0
#r "nuget: DvBCrud.API, 1.1.0"
#:package DvBCrud.API@1.1.0
#addin nuget:?package=DvBCrud.API&version=1.1.0
#tool nuget:?package=DvBCrud.API&version=1.1.0
DvBCrud.API
Library for rapidly developing CRUD API-endpoints for database entities.
Table of Contents
How it works
DvBCrud.EFCore.API is a complement to DvBCrud.EFCore for streamlining development of CRUD APIs.
The CRUDController comes in two flavors: the synchronous CRUDController and the asynchronous AsyncCRUDController.
Depending on your needs and use-case, you may use one or both of them.
Both controller types implement the following actions:
- CREATE:
POST /customer/ - READ:
GET /customer/{id} - LIST:
GET /customer/ - UPDATE:
PUT /customer/{id} - DELETE:
DELETE /customer/{id}
Getting started
1. Create entity, model, mapper and repository
Follow this guide to create your entities and your repository.
2. Create a CRUDController
Create the CRUDController for the entity and its repository
AnyController.cs
public class AnyController : CrudController<long, AnyModel, AnyRepository>
{
public AnyController(AnyRepository repository) : base(repository)
{
}
}
3. Use it
If you're using services.AddControllers() in Startup.cs, you're good to go.
The controller is now up and running on your application.
Restricting actions
You can restrict which actions are permitted by adding the CrudActionAttribute on the class. When a forbidden action is requested, the endpoint will return a 403 FORBIDDEN response.
If the attribute is not defined, the controller will default to allow all actions.
Here are some examples:
Read-only endpoint
AnyController.cs
[AllowedActions(CRUDAction.Read)]
public class AnyController : CrudController<long, AnyModel, AnyRepository>
{
public AnyController(AnyRepository repository) : base(repository)
{
}
}
Non-deletable endpoint
AnyController.cs
[AllowedActions(CRUDAction.Create | CRUDAction.Read | CRUDAction.Update)]
public class AnyController : CrudController<long, AnyModel, AnyRepository>
{
public AnyController(AnyRepository repository) : base(repository)
{
}
}
Hide restricted actions in Swagger Docs
To hide the restricted actions in Swagger UI, you need to add the SwaggerDocsFilter when declaring Swagger in Program.cs like so:
...
services.AddSwaggerGen(c => {
c.DocumentFilter<SwaggerDocsFilter>();
}
...
API Example
You can find a fully-implemented working API example in the DvBCrud.API.Tests.Web project.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- DvBCrud.Shared (>= 1.0.0)
- Microsoft.AspNetCore.Mvc.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Swashbuckle.AspNetCore.SwaggerGen (>= 6.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.0 | 241 | 9/24/2023 |
| 1.1.0-rc.2 | 133 | 9/23/2023 |
| 1.1.0-rc.1 | 126 | 9/23/2023 |
| 1.1.0-alpha.2 | 132 | 9/23/2023 |
| 1.1.0-alpha.1 | 155 | 7/10/2023 |
| 1.0.1 | 256 | 7/10/2023 |
| 1.0.1-rc.1 | 153 | 7/10/2023 |
| 1.0.0 | 240 | 7/9/2023 |
| 1.0.0-rc.1 | 151 | 7/9/2023 |
| 1.0.0-alpha.1 | 156 | 7/9/2023 |