Skip to content

Instantly share code, notes, and snippets.

@dj-nitehawk
Last active January 17, 2024 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dj-nitehawk/5b3e73818f630c2fe90d9f4674847452 to your computer and use it in GitHub Desktop.
Save dj-nitehawk/5b3e73818f630c2fe90d9f4674847452 to your computer and use it in GitHub Desktop.
Endpoint Grouping With FastEndpoints
using FastEndpoints;
using FastEndpoints.Swagger;
var bld = WebApplication.CreateBuilder();
bld.Services
.AddAuthorization()
.AddFastEndpoints()
.SwaggerDocument(o => o.AutoTagPathSegmentIndex = 0);
var app = bld.Build();
app.UseAuthorization()
.UseFastEndpoints()
.UseSwaggerGen();
app.Run();
public class Administration : Group
{
public Administration()
{
Configure(
"admin",
ep =>
{
ep.Description(
x => x.Produces(401)
.WithTags("administration"));
});
}
}
public class Login : EndpointWithoutRequest
{
public override void Configure()
{
Get("/login");
Group<Administration>();
}
public override async Task HandleAsync(CancellationToken c)
{
await SendOkAsync();
}
}
public class Sales : SubGroup<Administration>
{
public Sales()
{
Configure(
"sales",
ep =>
{
ep.Description(
x => x.Produces(402)
.WithTags("sales"));
});
}
}
public class GetInvoice : EndpointWithoutRequest
{
public override void Configure()
{
Get("/invoice/{id}");
Group<Sales>();
}
public override async Task HandleAsync(CancellationToken c)
{
await SendOkAsync();
}
}
public class Reports : SubGroup<Sales>
{
public Reports()
{
Configure(
"reports",
ep =>
{
ep.Description(
x => x.Produces(403)
.WithTags("sales-reports"));
});
}
}
public class TotalTurnover : EndpointWithoutRequest
{
public override void Configure()
{
Get("/turnover/{month}");
Group<Reports>();
}
public override async Task HandleAsync(CancellationToken c)
{
await SendOkAsync();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment