EndpointMapper 1.0.0

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

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

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");
    }
}

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

[^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.

Version Downloads Last updated
2.0.0 1,165 11/14/2023
2.0.0-prerelease.4 84 10/24/2023
2.0.0-prerelease.3 106 8/15/2023
2.0.0-prerelease.2 110 3/29/2023
2.0.0-prerelease.1 124 3/25/2023
1.0.1 276 12/8/2022
1.0.0 254 12/8/2022