https://github.com/hona/endpoints
A minimal source generator that decouples endpoint definition from wiring up to the host
https://github.com/hona/endpoints
Last synced: about 2 months ago
JSON representation
A minimal source generator that decouples endpoint definition from wiring up to the host
- Host: GitHub
- URL: https://github.com/hona/endpoints
- Owner: Hona
- License: mit
- Created: 2024-07-13T01:40:51.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-07-20T01:03:16.000Z (10 months ago)
- Last Synced: 2025-04-05T12:39:13.941Z (about 2 months ago)
- Language: C#
- Size: 13.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Endpoints
A minimal source generator that decouples endpoint definition from wiring up to the host## Installation
Add the `Hona.Endpoints` NuGet package.
In your application, implement the `IEndpoint` interface and define your endpoints.
```csharp
public class Adder : IEndpoint
{
public static void Map(IEndpointRouteBuilder endpoints)
{
endpoints.MapGet("/add", (int a, int b) => (a + b).ToString());
}
}
```Finally, one line to wire up all IEndpoint implementations:
```csharp
app.MapEndpoints();
```That's it.
## Extensions
This GitHub repo also contains the Mediator extensions for Hona.Endpoints.
Add the `Hona.Endpoints.Extensions.Mediator` NuGet package.
With the Mediator extensions, you can easily define endpoints that use REPR over Mediator.
```csharp
endpoints
.MapCommandPost("/todos")
.WithTags("Todos")
.WithDescription("Create a new todo, somehow.")
.AllowAnonymous();
```without the extensions, you would have to do this:
```csharp
endpoints
.MapPost(
"/todos",
(
Mediator.Mediator mediator,
CancellationToken cancellationToken,
[FromBody] Request request
) => mediator.Send(request, cancellationToken)
)
.Produces((int)HttpStatusCode.Created)
.WithTags("Todos")
.WithDescription("Create a new todo, somehow.")
.AllowAnonymous();
```