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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Branch | Status |
---|---|
main |
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
andRouteGroup
on demand to set endpoint route. - Override
ConfigureRoute
andConfigureRouteGroup
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 theProgram.cs
file from theWebApplication
instance. For example,
var app = builder.Build();
app.MapSharpEndpointFragmentsFromAssembly(typeof(Program).Assembly);
Default Choices
- The default
Route
andRouteGroup
arestring.Empty
- OpenAPI is enabled by default on both
Route
andRouteGroup
byWithOpenApi()
inConfigureRoute
andConfigureRouteGroup
- To use the default configurations, use
..base.Configure()
in the returnIEnumerable
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 | Versions 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.
-
net8.0
- Microsoft.AspNetCore.OpenApi (>= 8.0.7)
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 | 144 | 7/12/2024 |