SharpEndpoint 0.0.2

dotnet add package SharpEndpoint --version 0.0.2                
NuGet\Install-Package SharpEndpoint -Version 0.0.2                
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="SharpEndpoint" Version="0.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SharpEndpoint --version 0.0.2                
#r "nuget: SharpEndpoint, 0.0.2"                
#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 SharpEndpoint as a Cake Addin
#addin nuget:?package=SharpEndpoint&version=0.0.2

// Install SharpEndpoint as a Cake Tool
#tool nuget:?package=SharpEndpoint&version=0.0.2                
Branch Status
main Dotnet 8

Installation

  • SharpEndpoint is a C# library based on minimal API that offers an opinionated way to organize minimal API endpoints.
  • To install, run dotnet add package SharpEndpoint or from Nuget

Usage Guide

  • Crate a class and inherit it from SharpEndpointFragment, then implement the required methods.
  • Override Route and RouteGroup on demand to set endpoint route.
  • Override ConfigureRoute and ConfigureRouteGroup for providing configurations.
  • Constructor dependency injection is not allowed by design to stick with the minimal API convention.
  • To map all the endpoints, Call MapSharpEndpointFragmentsFromAssembly in the Program.cs file from the WebApplication instance. For example,
var app = builder.Build();
app.MapSharpEndpointFragmentsFromAssembly(typeof(Program).Assembly);

Default Choices

  • The default Route and RouteGroup are string.Empty
  • OpenAPI is enabled by default on both Route and RouteGroup by WithOpenApi() in ConfigureRoute and ConfigureRouteGroup
  • To use the default configurations, use ..base.Configure() in the return IEnumerable

Examples

  • A complete REST API with CRUD functionality example is also given to showcase the usefulness of SharpOutcome. Source code is available here.
public class Update : SharpEndpointFragment
{
    protected override string RouteGroup() => BookRouteConstants.BaseRoute;

    protected override string Route() => BookRouteConstants.IdParam;

    protected override HttpVerb Verb() => HttpVerb.PUT;

    protected override IEnumerable<Action<RouteHandlerBuilder>> ConfigureRoute()
    {
        return
        [
            ..base.ConfigureRoute(),
            e => e.WithSummary("update a book"),
            e => e.Produces(StatusCodes.Status200OK),
            e => e.Produces(StatusCodes.Status404NotFound),
            e => e.Produces(StatusCodes.Status304NotModified),
            e => e.AddEndpointFilter<FluentValidationFilter<CreateOrUpdateBookRequest>>()
        ];
    }

    protected override Delegate RequestHandler()
    {
        return async ([FromRoute] int id, [FromServices] IBookService bookService,
            [FromBody] CreateOrUpdateBookRequest dto) =>
        {
            var result = await bookService.UpdateAsync(id, dto);

            return result.Match<IResult>(
                entity => TypedResults.Json(data: entity, statusCode: StatusCodes.Status200OK),
                err => TypedResults.Json(data: err, statusCode: StatusCodes.Status304NotModified)
            );
        };
    }
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.

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
0.0.2 135 7/12/2024