ChrisMavrommatis.Endpoints
1.0.0
See the version list below for details.
dotnet add package ChrisMavrommatis.Endpoints --version 1.0.0
NuGet\Install-Package ChrisMavrommatis.Endpoints -Version 1.0.0
<PackageReference Include="ChrisMavrommatis.Endpoints" Version="1.0.0" />
paket add ChrisMavrommatis.Endpoints --version 1.0.0
#r "nuget: ChrisMavrommatis.Endpoints, 1.0.0"
// Install ChrisMavrommatis.Endpoints as a Cake Addin #addin nuget:?package=ChrisMavrommatis.Endpoints&version=1.0.0 // Install ChrisMavrommatis.Endpoints as a Cake Tool #tool nuget:?package=ChrisMavrommatis.Endpoints&version=1.0.0
Endpoints
ChrisMavrommatis.Endpoints
is a .NET Package aimed to provide the Endpoint pattern in your projects.
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 | 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. |
-
net8.0
- Swashbuckle.AspNetCore.SwaggerGen (>= 6.6.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.