ChrisMavrommatis.Endpoints
2.0.1
dotnet add package ChrisMavrommatis.Endpoints --version 2.0.1
NuGet\Install-Package ChrisMavrommatis.Endpoints -Version 2.0.1
<PackageReference Include="ChrisMavrommatis.Endpoints" Version="2.0.1" />
paket add ChrisMavrommatis.Endpoints --version 2.0.1
#r "nuget: ChrisMavrommatis.Endpoints, 2.0.1"
// Install ChrisMavrommatis.Endpoints as a Cake Addin #addin nuget:?package=ChrisMavrommatis.Endpoints&version=2.0.1 // Install ChrisMavrommatis.Endpoints as a Cake Tool #tool nuget:?package=ChrisMavrommatis.Endpoints&version=2.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 also 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.
Example Endpoints
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 ...
}
}
Namespace Route Token
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 | Versions 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. net9.0 is compatible. |
-
net8.0
- Swashbuckle.AspNetCore.SwaggerGen (>= 7.0.0)
-
net9.0
- Swashbuckle.AspNetCore.SwaggerGen (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.