Simple package to configure API endpoints as individual classes based on minimal Api (.Net 6)
License
—
Deps
1
Install Size
—
Vulns
✓ 0
Published
Jan 14, 2023
$ dotnet add package MinimalApi.EndpointThe goal of this project it's to show how to use MinimalApi.Endpoint package.
It demontrate how to configure API endpoints as individual classes based on minimal Api (.Net 6)
Use AddEndpoints extenion method to create each endpoint.
And also MapEndpoint extension method to use new routing APIs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpoints();
var app = builder.Build();
app.MapEndpoints();
app.Run();
To create and define one endpoint, it needs to implement IEndpoint interface
public class GetWithParamEndpoint : IEndpoint<string, string>
{
public void AddRoute(IEndpointRouteBuilder app)
{
app.MapGet("/Todo/2/{param1}", (string param1) => HandleAsync(param1));
}
public Task<string> HandleAsync(string request)
{
return Task.FromResult($"Hello World! 2 {request}");
}
}
eShopOnWeb: Sample ASP.NET Core reference application, powered by Microsoft
EshopOnVue.js: Same as EshopOnWeb project in Vue.js
StructuredMinimalApi: Sample project to show some usage
WebApiBestPractices: Resources related to Ardalis Pluralsight course on this topic.
A nuget package is available here.