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
<PackageReference Include="Easy.Endpoints.Core" Version="4.0.0" />
<PackageVersion Include="Easy.Endpoints.Core" Version="4.0.0" />
<PackageReference Include="Easy.Endpoints.Core" />
paket add Easy.Endpoints.Core --version 4.0.0
#r "nuget: Easy.Endpoints.Core, 4.0.0"
#:package Easy.Endpoints.Core@4.0.0
#addin nuget:?package=Easy.Endpoints.Core&version=4.0.0
#tool nuget:?package=Easy.Endpoints.Core&version=4.0.0
Easy.Endpoints
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 | Versions 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. |
-
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.