Easy.Endpoints.Core 4.0.0

dotnet add package Easy.Endpoints.Core --version 4.0.0
                    
NuGet\Install-Package Easy.Endpoints.Core -Version 4.0.0
                    
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="Easy.Endpoints.Core" Version="4.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Easy.Endpoints.Core" Version="4.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Easy.Endpoints.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Easy.Endpoints.Core --version 4.0.0
                    
#r "nuget: Easy.Endpoints.Core, 4.0.0"
                    
#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.
#:package Easy.Endpoints.Core@4.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Easy.Endpoints.Core&version=4.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Easy.Endpoints.Core&version=4.0.0
                    
Install as a Cake Tool

Easy.Endpoints

Quality Gate Status
Aspnetcore endpoints without the controller.
Docs
Sample Project

Setup

Add Easy.Endpoint services

    services.AddRequestEndpoints();

Add Easy.Endpoint to the application builder

app.UseEndpoints(endpoints =>  
  {  
    endpoints.AddEasyEndpoints();  
  });

And it will grab all implementations of IEndpoint. IEndpoint is expected to implement a single public method named Handle or HandleAsync Can extract paramters from route, body, query parameters and from HttpContext

Sample

Simple endpoint that will be grouped in swagger under Greetings

[EndpointController("Greetings")]  
public class HelloWorldEndpoint : IEndpoint  
{  
    public string Handle()  => "Hello World";
}

GET: /Book Returns a list of books in json format

public class GetBookEndpointHandler : IEndpoint
{
    public Task<Book[]> HandleAsync() => Task.FromResult(Array.Empty<Book>());
}

POST: /Book Accepts a Book in the body as Json and returns a Command Result

public class PostBookEndpointHandler : IEndpoint
{
    public PostBookEndpointHandler()
    {            
    }

    public Task<CommandResult> HandleAsync(Book body)
    {
        return Task.FromResult(new CommandResult { Successful = true, Message = "Yay!" });
    }
}

POST: /TestOne Alternatively can declare route and Method

[Post("TestOne")]
public class PostTestResponseEndpoint : IEndpoint
{
    public Task HandleAsync(TestResponsePayload body)
    {
        return Task.CompletedTask;
    }
}

Generic handler

Can declare generic handlers that can build routes for types
POST: /Animal/Cow
POST: /Animal/Dog

[EndpointController("Animal")]
[KnownTypes("Cow", typeof(Cow))]
[KnownTypes("Dog", typeof(Dog))]
[Post("[controller]/[type]")]
public class AnimalEndpointHandler<TAnimal> : IEndpoint where TAnimal : IAnimal
{
    public Task<string> HandleAsync(TAnimal body, CancellationToken cancellationToken)
    {
        return Task.FromResult(body.Says());
    }
}

EndpointResults

Handlers can return IEndpointResult for when more control over the end result is required.

[ProducesResponseType(200,Type = typeof(People))]  
[ProducesResponseType(404, Type = typeof(void))]  
[Get("People/{id:int}")]  
public class GetPeopleByIdEndpointHandler : IEndpoint  
{   
    private readonly IPeopleService peopleService

    public GetPeopleByIdEndpointHandler(IPeopleService peopleService)
    {
        this.peopleService = peopleService
    }

    public Task<IEndpointResult> HandleAsync(int id, CancellationToken cancellationToken)  
    {  
        var person = peopleService.AllPeople().SingleOrDefault(p => p.Id == id);  
        if (person is null)  
            return Task.FromResult<IEndpointResult>(new NoContentResult(404));  
        return Task.FromResult<IEndpointResult>(new JsonContentResult<People>(person));  
    }  
}  
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 (1)

Showing the top 1 NuGet packages that depend on Easy.Endpoints.Core:

Package Downloads
Easy.Endpoints

AspNetCore endpoints without the controller

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.0 443 12/31/2021
3.1.0 421 12/2/2021