EndpointMapper 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package EndpointMapper --version 1.0.1                
NuGet\Install-Package EndpointMapper -Version 1.0.1                
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="EndpointMapper" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EndpointMapper --version 1.0.1                
#r "nuget: EndpointMapper, 1.0.1"                
#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.
// Install EndpointMapper as a Cake Addin
#addin nuget:?package=EndpointMapper&version=1.0.1

// Install EndpointMapper as a Cake Tool
#tool nuget:?package=EndpointMapper&version=1.0.1                

EndpointMapper

Build on top of Minimal APIs and easy to use

Installation

dotnet add package EndpointMapper

Requiments

  • .NET 7

Usage

Simple add

  • builder.Services.AddEndpointMapper<T>();
  • app.UseEndpointMapper();
  • A class extending IEndpoint (see Samples for an example)

Note: If you want to use Swagger see this section under Advanced

Sample

Program.cs:

using EndpointMapper;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointMapper<Program>();

var app = builder.Build();

app.UseHttpsRedirection();

app.UseEndpointMapper();

app.Run();

ExampleEndpoint.cs:

using EndpointMapper;

public class ExampleEndpoint : IEndpoint
{
    [HttpMapGet("/example")]
    public Ok<string> Handle()
    {
        return TypedResults.Ok("Hello world from EndpointMapper");
    }
}

Note: If you want to bind values from the request into params of the request see this section under Advanced

Advanced

Swagger

You can use Swashbuckle.AspNetCore (and Microsoft.AspNetCore.OpenApi) and it will work out of the box.

Authentication

If you have authentication you need to add the SecurityDefinition(s) for swagger and an OperationFilter for swagger to get the requied values to see as secure each endpoint in the AddSwaggerGen configure action.

There is a OperationFilter into EndpointMapper to do add all the SecurityRequiments to the endpoints called SecureEndpointAuthRequirementFilter, you can use it by adding OperationFilter<SecureEndpointAuthRequirementFilter>() to the AddSwaggerGen() call.

Example of AddSwaggerGen call[^1]:

builder.Services.AddSwaggerGen(c =>
{
    c.OperationFilter<SecureEndpointAuthRequirementFilter>();

    c.AddSecurityDefinition("Bearer", new()
    {
        Name = "Bearer JWT",
        Type = SecuritySchemeType.Http,
        In = ParameterLocation.Header,
        Scheme = "Bearer"
    });
});
XML Documentation

You will need to add:

var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename), true);

Create your own IEndpointConfigurationAttribute

Simple create a class that extends Attribute and IEndpointConfigurationAttribute

IEndpointConfigurationAttribute requires you to implement a method called Configure where you have access to the RouteHandlerBuilder from ASP.NET, the rest is handled automatically

Create your own HttpMapAttribute

Simple create a class that extends HttpMapAttribute and use : base() on the constructor to pass the HttpVerb and the route(s), the rest is handled automatically

Parameters to the Handler Method

You can you use the method like it was an inline lambda from the MapGet() method on the WebApplication, so you can do:

  • Dependency Injection (from the method params)
  • Bind Query/Route/Body/Header values into params

Method based configuration

If you prefer you can implement a Configure method into the class that implement IEndpoint witch give you the ability to use the WebApplication to manually configure the routes and all the configuration to it

Warning: Doing this WILL cause a few thing to don't be respected, for example, the RoutePrefix will NOT be respected as the code to map the endpoint is not EndpointMapper but it's your implementation for the Configure method.

[^1]: See EndpointMapper.TestApplication/Program.cs for more.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
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.