MinimalApi.Endpoints 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package MinimalApi.Endpoints --version 1.0.4                
NuGet\Install-Package MinimalApi.Endpoints -Version 1.0.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MinimalApi.Endpoints" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MinimalApi.Endpoints --version 1.0.4                
#r "nuget: MinimalApi.Endpoints, 1.0.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MinimalApi.Endpoints as a Cake Addin
#addin nuget:?package=MinimalApi.Endpoints&version=1.0.4

// Install MinimalApi.Endpoints as a Cake Tool
#tool nuget:?package=MinimalApi.Endpoints&version=1.0.4                

MinimalApi.Endpoints

MinimalApi.Endpoints is a package that allows you to easily structure your Minimal Api Endpoints in individual classes instead of having them all in Program.cs.

Installation

You can install MinimalApi.Endpoints via NuGet Package Manager in Visual Studio or by using the following command:

dotnet add package MinimalApi.Endpoints

Usage

Simply call the MapEndpoints extension method in your Program.cs:

using MinimalApi;

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapEndpoints();

app.Run();

Then create a simple class that contains a method decorated with EndpointGet attribute:

public class GetUser
{
    [EndpointGet("/users/{id}")]
    public async Task<User> GetAsync(int id, UserDb db)
    {
        return await db.Users.FindAsync(id);
    }
}

You are free to put the class anywhere in your project, with any name and you can name the method whatever you like. Only requirement is to use appropriate Endpoint attribute.

Supported Endpoint attributes

  • EndpointGet for GET requests
  • EndpointPost for POST requests
  • EndpointPut for PUT requests

More examples

Here are some examples of using EndpointPost and EndpointPut:

public class CreateUser
{
    [EndpointPost("/users")]
    public async Task<User> PostAsync(User user, UserDb db)
    {
        db.Users.Add(user);
        await db.SaveChangesAsync();
        return user;
    }
}
public class UpdateUser
{
    [EndpointPut("/users/{id}")]
    public async Task<User> PutAsync(int id, User updatedUser, UserDb db)
    {
        var user = await db.Users.FindAsync(id);
        user.Name = updatedUser.Name;
        user.Email = updatedUser.Email;
        await db.SaveChangesAsync();
        return user;
    }
}

I want Controllers!

If you rather prefer to have all methods in one class:

public class WannaBeUserController
{
    [EndpointGet("/users/{id}")]
    public async Task<User> GetAsync(int id, UserDb db)
    {
        return await db.Users.FindAsync(id);
    }

    [EndpointPost("/users")]
    public async Task<User> PostAsync(User user, UserDb db)
    {
        db.Users.Add(user);
        await db.SaveChangesAsync();
        return user;
    }

    [EndpointPut("/users/{id}")]
    public async Task<User> PutAsync(int id, User updatedUser, UserDb db)
    {
        var user = await db.Users.FindAsync(id);
        user.Name = updatedUser.Name;
        user.Email = updatedUser.Email;
        await db.SaveChangesAsync();
        return user;
    }
}

Method parameters

The method parameters can resolve to route/query/body values and registered services from the dependency container.

Limitations

  • Only HTTP GET, POST, PUT methods are supported.
  • PATCH and DELETE will be supported when .NET 8 is released.

License

MinimalApi.Endpoints is licensed under the MIT license.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.1 452 9/15/2023
1.3.0 170 8/30/2023
1.2.0 390 5/23/2023
1.1.0 308 5/8/2023
1.0.4 158 5/8/2023
1.0.3 174 5/8/2023
1.0.2 191 4/24/2023
1.0.1 171 4/24/2023
1.0.0 175 4/24/2023