A set of extensions and helpers that extend the functionality of ASP.NET Core Minimal APIs.
This package is currently available from nuget.org:
> dotnet add package MinimalApis.Extensions
If you wish to use builds from this repo's main
branch you can install them from this repo's package feed.
Create a personal access token for your GitHub account with the read:packages
scope with your desired expiration length:
At the command line, navigate to your user profile directory and run the following command to add the package feed to your NuGet configuration, replacing the <GITHUB_USER_NAME>
and <PERSONAL_ACCESS_TOKEN>
placeholders with the relevant values:
~> dotnet nuget add source -n GitHub -u <GITHUB_USER_NAME> -p <PERSONAL_ACCESS_TOKEN> https://nuget.pkg.github.com/DamianEdwards/index.json
You should now be able to add a reference to the package specifying a version from the repository packages feed
See these instructions for further details about working with GitHub package feeds
> dotnet add package MinimalApis.Extensions
Program.cs
, call the AddEndpointsMetadataProviderApiExplorer()
method on builder.Services
to enable enhanced endpoint metadata in ApiExplorer
:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsMetadataProviderApiExplorer(); // <-- Add this line in .NET 6.0 projects
builder.Services.AddSwaggerGen();
...
app.MapPut("/todos/{id}", async Task<Results<NotFound, NoContent>> (int id, Todo todo, TodoDb db) =>
{
var existingTodo = await db.Todos.FindAsync(id);
if (existingTodo is null)
return TypedResults.NotFound();
existingTodo.Title = todo.Title;
existingTodo.IsCompleted = todo.IsCompleted;
await db.SaveChangesAsync();
return TypedResults.NoContent();
})
.WithParameterValidation();
This library provides types that help extend the core functionality of ASP.NET Core Minimal APIs in the following ways:
IParameterBinder
and Bind<TValue>
, Body<TValue>
, JsonFormFile
, and othersResults.Extensions
including PlainText
, Html
, and UnsupportedMediaType
IResult
objects for easier unit testing (available via TypedResults
) including the IStatusCodeHttpResult
, IContentTypeHttpResult
, and IValueHttpResult
interfacesIEndpointParameterMetadataProvider
and IEndpointMetadataProvider
IResult
return types via Results<TResult1, TResultN>
that enable route handler delegates to declare all the possible IResult
types they can return, enabling compile-time type checking and automatic population of all possible responses in Swagger/OpenAPI from type informationAn example Todos application using ASP.NET Core Minimal APIs and the Dapper library for data storage in SQLite.
Contains small examples for other types in this library.
Shows many examples of using the types in this library along with other things related to ASP.NET Core Minimal APIs.