MSHelper.WebApi
1.0.0
dotnet add package MSHelper.WebApi --version 1.0.0
NuGet\Install-Package MSHelper.WebApi -Version 1.0.0
<PackageReference Include="MSHelper.WebApi" Version="1.0.0" />
<PackageVersion Include="MSHelper.WebApi" Version="1.0.0" />
<PackageReference Include="MSHelper.WebApi" />
paket add MSHelper.WebApi --version 1.0.0
#r "nuget: MSHelper.WebApi, 1.0.0"
#:package MSHelper.WebApi@1.0.0
#addin nuget:?package=MSHelper.WebApi&version=1.0.0
#tool nuget:?package=MSHelper.WebApi&version=1.0.0
MSHelper.WebApi : Clean and robust API definition.
⭐ Star us on GitHub � it motivates us a lot!
Endpoints
With the usage of Web API package, you can define the endpoints more fluently, without the need of using a full ASP.NET Core MVC package and deriving from Controller. It�s more of an extension of the built-in IRouteBuilder abstraction allowing to define routing and deal with HTTP requests.
Installation
This document is for the latest MSHelper.WebApi 1.0.0 release and later.
dotnet add package MSHelper.WebApi
Dependencies
-- MSHelper
Usage
Extend Program.cs → CreateDefaultBuilder() with AddWebApi() that will add the required services.
public static IWebHostBuilder GetWebHostBuilder(string[] args)
=> WebHost.CreateDefaultBuilder(args)
.ConfigureServices(services => services
.AddMSHelper()
.AddWebApi()
.Build())
To define custom endpoints, invoke UseEndpoints() as the IApplicationBuilder extension within Configure() method. Then, you can make use of Get(), Post(), Put(), Delete() methods.
public static IWebHostBuilder GetWebHostBuilder(string[] args)
=> WebHost.CreateDefaultBuilder(args)
.ConfigureServices(services => services
.AddMSHelper()
.AddWebApi()
.Build())
.Configure(app => app
.UseEndpoints(endpoints => endpoints
.Get("", ctx => ctx.Response.WriteAsync("Hello"))
.Get<GetParcel, ParcelDto>("parcels/{parcelId}")
.Get<GetParcels, IEnumerable<ParcelDto>>("parcels")
.Delete<DeleteParcel>("parcels/{parcelId}")
.Post<AddParcel>("parcels", (req, ctx) => ctx.Response.Created($"parcels/{req.ParcelId}"))))
As you can see, generic extensions can be used when defining the endpoints (although it�s not required). Whenever you define a generic endpoint with a type T, it will bind the incoming request to the new instance of T (think of it as something similar to command).
To automatically handle the incoming request, you can implement IRequest marker interface for type T and create an IRequestHandler<T> that will be invoked automatically.
public class DeleteParcel : IRequest
{
public Guid ParcelId { get; }
public DeleteParcel(Guid parcelId)
{
ParcelId = parcelId;
}
}
public class DeleteParcelHandler : IRequestHandler<DeleteParcel, int>
{
public async Task<int> HandleAsync(DeleteParcel request)
{
// Deleted a parcel, let's return its ID.
return request.ParcelId;
}
}
Important Note:
All the MSHelper packages are for self learning purposes inspired by Devmentors.io
| 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
- MSHelper (>= 1.0.0)
- Open.Serialization.Json.System (>= 3.0.0)
- Open.Serialization.Json.Utf8Json (>= 3.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on MSHelper.WebApi:
| Package | Downloads |
|---|---|
|
MSHelper.WebApi.CQRS
MSHelper.WebApi.CQRS - CQRS Integration. |
|
|
MSHelper.WebApi.Swagger
MSHelper.WebApi.Swagger - Swagger Integration. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 486 | 10/25/2022 |