WART-Core
6.0.0
dotnet add package WART-Core --version 6.0.0
NuGet\Install-Package WART-Core -Version 6.0.0
<PackageReference Include="WART-Core" Version="6.0.0" />
<PackageVersion Include="WART-Core" Version="6.0.0" />
<PackageReference Include="WART-Core" />
paket add WART-Core --version 6.0.0
#r "nuget: WART-Core, 6.0.0"
#:package WART-Core@6.0.0
#addin nuget:?package=WART-Core&version=6.0.0
#tool nuget:?package=WART-Core&version=6.0.0
WART - WebApi Real Time
<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
- Installation
- How It Works
- Usage
- Supported Authentication Modes
- Excluding APIs from Event Propagation
- Group-based Event Dispatching
- NuGet
- Contributing
- License
- Contact
β¨ 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:
- Captures request and response data.
- Wraps them in a
WartEvent
. - 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:
- Setting up Git
- Fork the repository
- Open an issue if you encounter a bug or have a suggestion for improvements/features
- Submit a Pull Request.
π 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 | Versions 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. |
-
net9.0
- IdentityModel.AspNetCore.OAuth2Introspection (>= 6.2.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 9.0.8)
- System.Text.Json (>= 9.0.8)
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 |