DvBCrud.API 1.1.0

dotnet add package DvBCrud.API --version 1.1.0
                    
NuGet\Install-Package DvBCrud.API -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DvBCrud.API" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DvBCrud.API" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="DvBCrud.API" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DvBCrud.API --version 1.1.0
                    
#r "nuget: DvBCrud.API, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DvBCrud.API@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DvBCrud.API&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=DvBCrud.API&version=1.1.0
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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