ApiBolt.AspNetCore
0.1.0
See the version list below for details.
dotnet add package ApiBolt.AspNetCore --version 0.1.0
NuGet\Install-Package ApiBolt.AspNetCore -Version 0.1.0
<PackageReference Include="ApiBolt.AspNetCore" Version="0.1.0" />
paket add ApiBolt.AspNetCore --version 0.1.0
#r "nuget: ApiBolt.AspNetCore, 0.1.0"
// Install ApiBolt.AspNetCore as a Cake Addin #addin nuget:?package=ApiBolt.AspNetCore&version=0.1.0 // Install ApiBolt.AspNetCore as a Cake Tool #tool nuget:?package=ApiBolt.AspNetCore&version=0.1.0
ApiBolt
ApiBolt uses incremental source generators to generate Minimal API mapping for endpoints as Request-Endpoint-Response (REPR pattern).
Installing
To use the ApiBolt source generator, install the ApiBolt.AspNetCore
package and the ApiBolt.SourceGenerator
package into your API project.
dotnet add package ApiBolt.AspNetCore --version 0.0.1-beta.1
dotnet add package ApiBolt.SourceGenerator --version 0.0.1-beta.1
Usage
To use the ApiBolt package, register it to your API project.
Register the services and pass the assembly where the endpoints are located, in this case inside the API assembly.
builder.Services.AddApiBolt(typeof(Program).Assembly);
Map the endpoints
app.MapApiBolt();
Create an endpoint, add the IApiEndpoint
interface to it. This is used for DI registration. All services endpoints are registered as Scoped service.
Create a method which represents your API method, add the ApiEndpointAttribute
on the method. Specify the type of the call (GET, POST, PUT, DELETE) and the pattern for the API endpoint.
Get
internal class GetWeatherEndpoint : IApiEndpoint
{
[ApiEndpoint(ApiEndpointType.Get, "/weather")]
public string GetWeatherAsync()
{
return $"Current weather in AMS is 14 degrees celsius";
}
}
For above example, the source generator creates the following output.
public class GetWeatherEndpointRegistration : IApiEndpointRegistration
{
public void MapEndpoint(IEndpointRouteBuilder app)
{
app.MapGet("/weather", ([FromServices] GetWeatherEndpoint endpoint) => endpoint.GetWeatherAsync());
}
}
All the parameters passed into the method, are mapped to the API call. So for example
internal class GetWeatherForCityEndpoint : IApiEndpoint
{
[ApiEndpoint(ApiEndpointType.Get, "/weather/{city}")]
public string GetWeatherAsync(string city, [FromQuery] int temp)
{
return $"Current weather in {city} is {temp} degrees celsius";
}
}
Generates the following output.
public class GetWeatherForCityEndpointRegistration : IApiEndpointRegistration
{
public void MapEndpoint(IEndpointRouteBuilder app)
{
app.MapGet("/weather/{city}", (string city, [FromQuery] int temp, [FromServices] GetWeatherForCityEndpoint endpoint) => endpoint.GetWeatherAsync(city, temp));
}
}
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. |
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.