Skip to content

A source generator for .NET Minimal APIs to make building REST APIs easier for .NET

License

Notifications You must be signed in to change notification settings

IeuanWalker/MinimalApi.Endpoints

Repository files navigation

MinimalApi.Endpoints Nuget Nuget License: MIT

Read the docs

MinimalApi.Endpoints is a source generator that lets you write clean, class-based endpoints for .NET Minimal APIs - no runtime reflection, no boilerplate. Inspired by FastEndpoints, but fully source-generated and gives you complete control.

Why Use This?

  • 🚀 Zero Runtime Overhead - Everything is source-generated; no reflection, no hidden costs
  • 🏗️ Clean Architecture - Organise endpoints into testable, maintainable classes, which nudges you towards REPR Design Pattern (Request-Endpoint-Response) and Vertical Slice Architecture
  • 🔧 Full Control: Complete access to RouteHandlerBuilder and RouteGroupBuilder - it's just Minimal APIs underneath
  • 📁 Better Organization - Group endpoints clearly; perfect for large projects
  • ✅ Built-In Validation - Support DataAnnotations and FluentValidation out of the box
  • 🔓 No Lock-In - Copy the generated code and remove the library anytime - you own the output

How It Works (The wiki has the full explanation, but here's a quick overview)

  1. Create endpoint classes implementing one of the endpoint interfaces
  2. Source generator scans your assembly at compile time
  3. Generates extension methods for dependency injection and route mapping
  4. Call the extensions in your Program.cs:
var builder = WebApplication.CreateBuilder();
builder.AddEndpoints(); // Registers endpoints as services

var app = builder.Build();
app.MapEndpoints();     // Maps all routes

That's it! Your endpoints are now mapped with zero runtime reflection.

Full access to configure your endpoints

You have complete access to the RouteHandlerBuilder, so you can configure endpoints exactly like standard Minimal APIs:

public class HelloWorldEndpoint : IEndpoint<RequestModel, ResponseModel>
{
    public static void Configure(RouteHandlerBuilder builder)
    {
        builder
            .Post("/HelloWorld")
            .RequestFromBody()
            .WithName("CreateHelloWorld") // optional, automatically set for you if not set
            .WithTags("HelloWorld") // optional, automatically set for you if not set
            .WithSummary("Creates a hello world")
            .WithDescription("Creates a new world in the system")
            .Produces<ResponseModel>(201)
            .Produces(400)
            .Produces(409)
            .ProducesValidationProblem()
            .RequireAuthorization()
            .RequireCors("MyPolicy")
            .CacheOutput(TimeSpan.FromMinutes(5));
    }

    public async Task<ResponseModel> Handle(RequestModel request, CancellationToken ct)
    {
        // Your implementation
        return new ResponseModel();
    }
}

📖 Read Full Documentation & Examples →

Contributing

Contributions are welcome! Please feel free to open an issue or submit a Pull Request (start with an issue if it's a significant change).

License

This project is licensed under the MIT License.

About

A source generator for .NET Minimal APIs to make building REST APIs easier for .NET

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors 3

  •  
  •  
  •  

Languages