WART-Core 6.0.0

dotnet add package WART-Core --version 6.0.0
                    
NuGet\Install-Package WART-Core -Version 6.0.0
                    
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="WART-Core" Version="6.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WART-Core" Version="6.0.0" />
                    
Directory.Packages.props
<PackageReference Include="WART-Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WART-Core --version 6.0.0
                    
#r "nuget: WART-Core, 6.0.0"
                    
#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.
#:package WART-Core@6.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WART-Core&version=6.0.0
                    
Install as a Cake Addin
#tool nuget:?package=WART-Core&version=6.0.0
                    
Install as a Cake Tool

WART - WebApi Real Time

License: MIT Nuget NuGet Downloads issues - wart stars - wart Sponsor me

<img src="https://github.com/engineering87/WART/blob/develop/wart_logo.jpg" width="300">

WART is a lightweight C# .NET library that extends your Web API controllers to forward incoming calls directly to a SignalR Hub.
The Hub broadcasts rich, structured events containing request and response details in real-time.
Supports JWT and Cookie Authentication for secure communication.

πŸ“‘ Table of Contents

✨ Features

  • Converts REST API calls into SignalR events, enabling real-time communication.
  • Provides controllers (WartController, WartControllerJwt, WartControllerCookie) for automatic SignalR event broadcasting.
  • Supports JWT authentication for SignalR hub connections.
  • Allows API exclusion from event broadcasting with [ExcludeWart] attribute.
  • Enables group-specific event dispatching with [GroupWart("group_name")].
  • Configurable middleware (AddWartMiddleware) for flexible integration.

πŸ“¦ Installation

Install from NuGet

dotnet add package WART-Core

βš™οΈ How it works

WART overrides OnActionExecuting and OnActionExecuted in a custom base controller. For every API request/response:

  1. Captures request and response data.
  2. Wraps them in a WartEvent.
  3. Publishes it through a SignalR Hub to all connected clients.

πŸš€ Usage

Basic Setup

Extend your API controllers from WartController:

using WART_Core.Controllers;
using WART_Core.Hubs;

[ApiController]
[Route("api/[controller]")]
public class TestController : WartController
{
    public TestController(IHubContext<WartHub> hubContext, ILogger<WartController> logger)
        : base(hubContext, logger) { }
}

Register WART in Startup.cs:

using WART_Core.Middleware;

public void ConfigureServices(IServiceCollection services)
{
    services.AddWartMiddleware(); // No authentication
}

public void Configure(IApplicationBuilder app)
{
    app.UseWartMiddleware();
}

Using JWT Authentication

services.AddWartMiddleware(hubType: HubType.JwtAuthentication, tokenKey: "your_secret_key");
app.UseWartMiddleware(HubType.JwtAuthentication);

Extend from WartControllerJwt:

public class TestController : WartControllerJwt
{
    public TestController(IHubContext<WartHubJwt> hubContext, ILogger<WartControllerJwt> logger)
        : base(hubContext, logger) { }
}

Custom Hub Names

You can specify custom hub routes:

app.UseWartMiddleware("customhub");

Multiple Hubs

You can configure multiple hubs at once by passing a list of hub names:

var hubs = new[] { "orders", "products", "notifications" };

app.UseWartMiddleware(hubs);

This is useful for separating traffic by domain.

Client Example

Without authentication:
var hubConnection = new HubConnectionBuilder()
    .WithUrl("http://localhost:5000/warthub")
    .Build();

hubConnection.On<string>("Send", data =>
{
    // 'data' is a WartEvent JSON
});

await hubConnection.StartAsync();
With JWT authentication:
var hubConnection = new HubConnectionBuilder()
    .WithUrl("http://localhost:5000/warthub", options =>
    {
        options.AccessTokenProvider = () => Task.FromResult(GenerateToken());
    })
    .WithAutomaticReconnect()
    .Build();

hubConnection.On<string>("Send", data =>
{
    // Handle WartEvent JSON
});

await hubConnection.StartAsync();

πŸ” Supported Authentication Modes

Mode Description Hub Class Required Middleware
No Authentication Open access without identity verification WartHub None
JWT (Bearer Token) Authentication via JWT token in the Authorization: Bearer <token> header WartHubJwt UseJwtMiddleware()
Cookie Authentication Authentication via HTTP cookies issued after login WartHubCookie UseCookieMiddleware()

βš™οΈ Authentication mode is selected through the HubType configuration in the application startup.

🚫 Excluding APIs from Event Propagation

There might be scenarios where you want to exclude specific APIs from propagating events to connected clients. This can be particularly useful when certain endpoints should not trigger updates, notifications, or other real-time messages through SignalR. To achieve this, you can use a custom filter called ExcludeWartAttribute. By decorating the desired API endpoints with this attribute, you can prevent them from being included in the SignalR event propagation logic, for example:

[HttpGet("{id}")]
[ExcludeWart]
public ActionResult<TestEntity> Get(int id)
{
    var item = Items.FirstOrDefault(x => x.Id == id);
    if (item == null)
    {
        return NotFound();
    }
    return item;
}

πŸ‘₯ Group-based Event Dispatching

WART enables sending API events to specific groups in SignalR by specifying the group name in the query string. This approach allows for flexible and targeted event broadcasting, ensuring that only the intended group of clients receives the event. By decorating an API method with [GroupWart("group_name")], it is possible to specify the SignalR group name to which the dispatch of specific events for that API is restricted. This ensures that only the clients subscribed to the specified group ("SampleGroupName") will receive the related events, allowing for targeted, group-based communication in a SignalR environment.

[HttpPost]
[GroupWart("SampleGroupName")]
public ActionResult<TestEntity> Post([FromBody] TestEntity entity)
{
    Items.Add(entity);
    return entity;
}

By appending ?WartGroup=group_name to the URL, the library enables dispatching events from individual APIs to a specific SignalR group, identified by group_name. This allows for granular control over which clients receive the event, leveraging SignalR’s built-in group functionality.

πŸ“¦ NuGet

The library is available on NuGet.

🀝 Contributing

Contributions are welcome! Steps to get started:

πŸ“„ License

WART source code is available under MIT License, see license in the source.

πŸ“¬ Contact

Please contact at francesco.delre[at]protonmail.com for any details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
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
6.0.0 162 8/24/2025
5.3.4 126 12/11/2024
5.3.3 118 10/10/2024
5.3.2 113 9/8/2024
5.3.1 129 7/16/2024
5.3.0 125 6/17/2024
5.2.0 130 6/2/2024
5.1.0 129 4/25/2024
5.0.0 175 2/10/2024
4.0.0 211 10/16/2023
3.0.0 358 1/23/2023
2.0.0 535 4/10/2021
1.0.3 600 10/9/2020
1.0.2 587 5/24/2020
1.0.1 645 12/20/2019
1.0.0 701 12/15/2019