DataHead.ApiToolkit 1.0.0

dotnet add package DataHead.ApiToolkit --version 1.0.0
                    
NuGet\Install-Package DataHead.ApiToolkit -Version 1.0.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="DataHead.ApiToolkit" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DataHead.ApiToolkit" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DataHead.ApiToolkit" />
                    
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 DataHead.ApiToolkit --version 1.0.0
                    
#r "nuget: DataHead.ApiToolkit, 1.0.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 DataHead.ApiToolkit@1.0.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=DataHead.ApiToolkit&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DataHead.ApiToolkit&version=1.0.0
                    
Install as a Cake Tool

API Toolkit

This package contains a set of various tools that can be used during the development of a Web API.

Identity and Authentication

This package contains a permissions system build on top of .NET Identity. All that needs to be supplied is an Enum containing application permissions. An example enum is listed here:

public enum Permission
{
    CreateUsers = 101,
    ReadUsers = 102,
    UpdateUsers = 103,
    DeleteUsers = 104,
    CreateRoles = 201,
    ReadRoles = 202,
    UpdateRoles = 203,
    DeleteRoles = 204,
}

To set this up, make sure your database context extends IdentityDbContext and specifies the following types:

public class ApplicationContext : IdentityDbContext<IdentityUser, RoleWithPermissions<Permission>, string> {

}

The RoleWithPermissions model required a Permissions enum to be specified. You can use the default IdentityUser class or provide one of your own.

After this, you can call AddIdentity on the IServiceCollection using the RoleWithPermissions role class.

A helper function is included to configure authentication. You can call AddJwtAuthentication on the IServiceCollection and provide a secret, audience, and issuer in order to configure JWT authentication.

In order for the permissions policies to function, you must call two more functions on the service collection.

builder.Services.AddAuthorizationWithPerms<Permission>();
builder.Services.AddPermissionHandler<Permission, IdentityUser, RoleWithPermissions<Permission>>();

If you want to ensure a SuperAdmin role is always available, you can call the following function before app.Run() is called.

WebApplicationHelpers.GenerateDefaultRoles<Permission, RoleWithPermissions<Permission>>(builder.Services);

Make sure that authentication and authorization is set before the run function is called.

app.UseAuthentication();
app.UseAuthorization();

Models, View Models and the Generic Repository

A BaseModel class is provided for database models that provides CreatedAt and UpdatedAt date fields. If a model extends from this class, then these values are updated if saved through the GenericRepository class. The Generic Repository provides a repository class for creating and modifying database models. It also exposes the underlying query system if it needs to be used. You can add a repository to the IOC container using the code below:

builder.Services.AddScoped<IGenericRepository<MyModel>, GenericRepository<MyModel>>();

API Response and Pagination

An ApiResponse class is provided. This standardizes the format of an API response from the server.

A PaginatedData class also exists that formats data along with pagination information.

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.0.0 390 9/23/2022