An open API service indexing awesome lists of open source software.

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

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();
```