Quilt4Net.Toolkit.Api 0.0.21

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

// Install Quilt4Net.Toolkit.Api as a Cake Tool
#tool nuget:?package=Quilt4Net.Toolkit.Api&version=0.0.21                

Quilt4Net Toolkit Api

GitHub repo

Add configurable support for Health, Liveness, Readyness, Version and Metrics in .NET Web Applications.

Get started

After having installed the nuget package. Register AddQuilt4NetApi as a service and use it in the app.

var builder = WebApplication.CreateBuilder(args);
...
builder.AddQuilt4NetApi();

var app = builder.Build();
...
app.UseRouting();
...
app.UseQuilt4NetApi();

app.Run();

You have to call AddQuilt4NetApi in any order on the builder (or builder.Services). On the app you have to call UseRouting before UseQuilt4NetApi.

Register service check

This is a basic way of adding a service check. This check will be performed when calling Health, Ready or Dependencies.

builder.AddQuilt4NetApi(o =>
{
    o.AddComponent(new Component
    {
        Name = "some-service",
        Essential = true,
        CheckAsync = async _ =>
        {
            await Task.Delay(TimeSpan.FromSeconds(1));
            return new CheckResult { Success = true };
        }
    });
});

Configuration options

Configuration can be configured by code. This will override any other configuration.

builder.AddQuilt4NetApi(o =>
{
    o.ShowInSwagger = false;
    o.FailReadyWhenDegraded = true;
});

Configuration in appsettings.json.

{
  "Quilt4Net": {
    "ShowInSwagger": false,
    "FailReadyWhenDegraded" : true,
  }
}

For values without configuration default values are used.

  • ShowInSwagger: Turns on visibility in swagger.
  • FailReadyWhenDegraded: When calling Ready and the service is Degraded it sill by default return 200. If this is set to true, the response will be 503 for degraded components.

Endpoints

Use the endpoint in different scenarios.

Health

~/api/Health/health

Use this by ping-services to check that everything works as intended. It can also be used for smoke tests after release to assure that the service is working.

Liveness

~/api/Health/live

Use this endpoint to check if a new instance sould be started. Commonly used in kubernetes or Azure to make sure the correct number of pods or machines are active.

Readyness

~/api/Health/ready

Use this endpoint to check if the instance is ready to perform work.

Troubleshooting

Error at startup with the message: Unhandled exception. System.InvalidOperationException: EndpointRoutingMiddleware matches endpoints setup by EndpointMiddleware and so must be added to the request execution pipeline before EndpointMiddleware. Please add EndpointRoutingMiddleware by calling 'IApplicationBuilder.UseRouting' inside the call to 'Configure(...)' in the application startup code.

The solution is to add app.UseRouting(); before app.UseQuilt4NetApi(); in Program.cs.

Planned

  • IP-Address lookup
  • Authentication for endpoints (Use project auth or API-Key for different methods.)
  • Feature to check if background services are running or if they have crashed.
  • Monitor service that can be implemented so that components does not have to be added with 'AddComponent' in 'AddQuilt4NetApi'.
  • Possible to create custom implementation of services

Support for API health, liveness, readiness, startup, metrics, version and dependencies.

Read more on the project site.

GitHub repo

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.  net9.0 is compatible. 
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.21 32 11/27/2024
0.0.20 61 11/27/2024
0.0.19 110 11/26/2024
0.0.18 79 11/23/2024
0.0.17 75 11/21/2024
0.0.14 72 11/18/2024
0.0.12 91 11/18/2024
0.0.10 90 11/17/2024
0.0.7 68 11/17/2024