ApiBolt 0.3.1

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

// Install ApiBolt as a Cake Tool
#tool nuget:?package=ApiBolt&version=0.3.1                

<img src="https://raw.githubusercontent.com/mvput/ApiBolt/main/logo.png" alt="drawing" width="200"/>

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.3.1
dotnet add package ApiBolt.SourceGenerator --version 0.3.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
{
    [HttpGet("/weather"), ApiEndpoint]
    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
{
    [HttpGet("/weather/{city}"), ApiEndpoint]
    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));
    }
}

To configure the endpoint after the Map, add the IApiEndpointConvention interface and add the `` method

internal class GetWeatherEndpoint : IApiEndpoint, IApiEndpointConvention
{
    [HttpGet("/weather"), ApiEndpoint]
    public string GetWeatherAsync()
    {
        return $"Current weather in AMS is 14 degrees celsius";

    }
    public static void Configure(IEndpointConventionBuilder builder)
    {
        builder.RequireAuthorization(policy => policy.RequireAuthenticatedUser());
    }
}

Generates the following output.

public class GetWeatherEndpointRegistration : IApiEndpointRegistration
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        var builder = app.MapGet("/weather", ([FromServices] GetWeatherEndpoint endpoint) => endpoint.GetWeatherAsync());
        GetWeatherEndpoint.Configure(builder);
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ApiBolt:

Package Downloads
ApiBolt.AspNetCore

ApiBolt uses incremental source generators to generate Minimal API mapping for endpoints as Request-Endpoint-Response (REPR pattern).

ApiBolt.SourceGenerator

ApiBolt uses incremental source generators to generate Minimal API mapping for endpoints as Request-Endpoint-Response (REPR pattern).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.1 123 11/25/2024
0.3.0 124 11/22/2024
0.2.1 144 11/8/2024
0.2.0 124 11/8/2024
0.1.0 169 10/23/2024