ChrisMavrommatis.Endpoints 1.0.1

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

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

Endpoints

ChrisMavrommatis.Endpoints is a .NET Package aimed to provide the Endpoint pattern in your projects while using classic Controllers behind the scenes.

The project aims to provide with utilities that will make your API structure look like this

Endpoints
 - Users
    - Get.cs
    - List.cs
    - Create.cs
    - Delete.cs
  - Products
    - Get.cs
    - List.cs
    - Create.cs
    - Delete.cs

Installation

Install the package via NuGet Package Manager

Install-Package ChrisMavrommatis.Endpoints

Or via .NET CLI:

dotnet add package ChrisMavrommatis.Endpoints

Usage

The library masks the ControllerBase class in several layers ending up with the following classes:

  • EndpointWithoutRequest
  • EndpointWithRequest<TRequest>

There is an additional option to define the namespace of the endpoint by using the [Route] attribute. The [namespace] placeholder will be replaced with the namespace of the endpoint.

For example the List.cs file would look like this:

namespace MyProject.Endpoints.Users;

[Route("api/[namespace]")]
public class List : EndpointWithoutRequest
{
  
  // GET: api/Users
  [HttpGet]
  public override Task<IActionResult> HandleAsync()
  {
    // Code ...
  }
}

The Get.cs file would look like this:

namespace MyProject.Endpoints.Users;

[Route("api/[namespace]")]
public class Get : EndpointWithRequest<GetUserRequest>
{
  
  // GET: api/Users/{id}
  [HttpGet("{id}")]
  public override Task<IActionResult> HandleAsync(GetUserRequest request)
  {
    // Code ...
  }
}

The Create.cs file would look like this:

namespace MyProject.Endpoints.Users;

[Route("api/[namespace]")]
public class Create : EndpointWithRequest<CreateUserRequest>
{
  
  // POST: api/Users
  [HttpPost]
  public override Task<IActionResult> HandleAsync(CreateUserRequest request)
  {
    // Code ...
  }
}

In order to use the Namespace route you need to use the UseNamespaceRouteToken extension method while adding controllers

builder.Services.AddControllers(options =>
{
  options.UseNamespaceRouteToken();
})

And while configuring the SwaggerGenOptions use the TagActionsByEndpointNamespaceOrDefault extension method

builder.Services.AddSwaggerGen(options =>
{
  options.TagActionsByEndpointNamespaceOrDefault();
})

License

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.1 80 11/25/2024
2.0.0 76 11/13/2024
1.0.1 257 7/24/2024
1.0.0 75 7/24/2024