{"id":21670507,"url":"https://github.com/engineering87/wart","last_synced_at":"2025-08-04T21:45:44.052Z","repository":{"id":36530569,"uuid":"223401617","full_name":"engineering87/WART","owner":"engineering87","description":"Turns WebApi calls into SignalR events","archived":false,"fork":false,"pushed_at":"2024-04-25T17:46:04.000Z","size":594,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2024-04-26T17:49:52.077Z","etag":null,"topics":["c-sharp","netcore","publish-subscribe","signalr","webapi"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/engineering87.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-22T12:46:57.000Z","updated_at":"2024-06-02T19:22:38.620Z","dependencies_parsed_at":"2024-06-02T19:22:37.000Z","dependency_job_id":"1978783c-5586-4577-9064-b133604ae18f","html_url":"https://github.com/engineering87/WART","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engineering87%2FWART","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engineering87%2FWART/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engineering87%2FWART/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/engineering87%2FWART/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/engineering87","download_url":"https://codeload.github.com/engineering87/WART/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248507468,"owners_count":21115607,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","netcore","publish-subscribe","signalr","webapi"],"created_at":"2024-11-25T12:32:43.934Z","updated_at":"2025-08-04T21:45:44.034Z","avatar_url":"https://github.com/engineering87.png","language":"C#","readme":"# WART - WebApi Real Time\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Nuget](https://img.shields.io/nuget/v/WART-Core?style=plastic)](https://www.nuget.org/packages/WART-Core)\n![NuGet Downloads](https://img.shields.io/nuget/dt/WART-Core)\n[![issues - wart](https://img.shields.io/github/issues/engineering87/WART)](https://github.com/engineering87/WART/issues)\n[![stars - wart](https://img.shields.io/github/stars/engineering87/WART?style=social)](https://github.com/engineering87/WART)\n[![Sponsor me](https://img.shields.io/badge/Sponsor-❤-pink)](https://github.com/sponsors/engineering87)\n\n\u003cimg src=\"https://github.com/engineering87/WART/blob/develop/wart_logo.jpg\" width=\"300\"\u003e\n\nWART is a C# .NET library that enables you to extend any Web API controller and forward incoming calls directly to a SignalR hub. This hub then broadcasts notifications containing detailed information about the calls, including both the request and the response. Additionally, WART supports JWT authentication for secure communication with SignalR.\n\n## Features\n- Converts REST API calls into SignalR events, enabling real-time communication.\n- Provides controllers (`WartController`, `WartControllerJwt`, `WartControllerCookie`) for automatic SignalR event broadcasting.\n- Supports JWT authentication for SignalR hub connections.\n- Allows API exclusion from event broadcasting with `[ExcludeWart]` attribute.\n- Enables group-specific event dispatching with `[GroupWart(\"group_name\")]`.\n- Configurable middleware (`AddWartMiddleware`) for flexible integration.\n\n## Installation\nYou can install the library via the NuGet package manager with the following command:\n\n```bash\ndotnet add package WART-Core\n```\n\n### How it works\nWART implements a custom controller which overrides the `OnActionExecuting` and `OnActionExecuted` methods to retrieve the request and the response and encapsulates them in a **WartEvent** object which will be sent via SignalR on the **WartHub**.\n\n### How to use it\n\nTo use the WART library, each WebApi controller must extend the **WartController** controller:\n\n```csharp\nusing WART_Core.Controllers;\nusing WART_Core.Hubs;\n\n[ApiController]\n[Route(\"api/[controller]\")]\npublic class TestController : WartController\n```\n\neach controller must implement the following constructor, for example:\n\n```csharp\npublic TestController(IHubContext\u003cWartHub\u003e messageHubContext, \nILogger\u003cWartController\u003e logger) : base(messageHubContext, logger)\n{\n}\n```\n\nWART support JWT bearer authentication on SignalR hub, if you want to use JWT authentication use the following controller extension:\n\n```csharp\nusing WART_Core.Controllers;\nusing WART_Core.Hubs;\n\n[ApiController]\n[Route(\"api/[controller]\")]\npublic class TestController : WartControllerJwt\n```\n\nYou also need to enable SignalR in the WebAPI solution and map the **WartHub**.\nTo do this, add the following configurations in the Startup.cs class:\n\n```csharp\nusing WART_Core.Middleware;\n```\n\nIn the ConfigureServices section add following:\n\n```csharp\nservices.AddWartMiddleware();\n```\n\nor by specifying JWT authentication:\n\n\n```csharp\nservices.AddWartMiddleware(hubType:HubType.JwtAuthentication, tokenKey:\"password_here\");\n```\n\nIn the Configure section add the following:\n\n```csharp\napp.UseWartMiddleware();\n```\n\nor by specifying JWT authentication:\n\n```csharp\napp.UseWartMiddleware(HubType.JwtAuthentication);\n```\n\nAlternatively, it is possible to specify a custom hub name:\n\n```csharp\napp.UseWartMiddleware(\"hubname\");\n```\n\nat this point it will be sufficient to connect via SignalR to the WartHub to receive notifications in real time of any call on the controller endpoints. \nFor example:\n\n```csharp\nvar hubConnection = new HubConnectionBuilder()\n    .WithUrl(\"http://localhost:52086/warthub\")\n    .Build();\n    \nhubConnection.On\u003cstring\u003e(\"Send\", (data) =\u003e\n{\n  // data is the WartEvent JSON\n});\n```\n\nor with JWT authentication:\n\n```csharp\nvar hubConnection = new HubConnectionBuilder()\n    .WithUrl($\"http://localhost:51392/warthub\", options =\u003e\n    {\n        options.SkipNegotiation = true;\n        options.Transports = HttpTransportType.WebSockets;\n        options.AccessTokenProvider = () =\u003e Task.FromResult(GenerateToken());\n    })\n    .WithAutomaticReconnect()\n    .Build();\n    \nhubConnection.On\u003cstring\u003e(\"Send\", (data) =\u003e\n{\n  // data is the WartEvent JSON\n});\n```\n\nIn the source code you can find a simple test client and WebApi project.\n\n## Supported Authentication Modes\n\nThe project supports three authentication modes for accessing the SignalR Hub:\n\n| Mode                     | Description                                                               | Hub Class           | Required Middleware      |\n|--------------------------|---------------------------------------------------------------------------|----------------------|---------------------------|\n| **No Authentication**    | Open access without identity verification                                 | `WartHub`            | None                      |\n| **JWT (Bearer Token)**   | Authentication via JWT token in the `Authorization: Bearer \u003ctoken\u003e` header | `WartHubJwt`         | `UseJwtMiddleware()`      |\n| **Cookie Authentication**| Authentication via HTTP cookies issued after login                        | `WartHubCookie`      | `UseCookieMiddleware()`   |\n\n\u003e ⚙️ Authentication mode is selected through the `HubType` configuration in the application startup.\n\n### Excluding APIs from Event Propagation\nThere 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:\n\n```csharp\n[HttpGet(\"{id}\")]\n[ExcludeWart]\npublic ActionResult\u003cTestEntity\u003e Get(int id)\n{\n    var item = Items.FirstOrDefault(x =\u003e x.Id == id);\n    if (item == null)\n    {\n        return NotFound();\n    }\n    return item;\n}\n```\n\n### SignalR Event Dispatching for Specific Groups\nWART 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. \nBy 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.\n\n```csharp\n[HttpPost]\n[GroupWart(\"SampleGroupName\")]\npublic ActionResult\u003cTestEntity\u003e Post([FromBody] TestEntity entity)\n{\n    Items.Add(entity);\n    return entity;\n}\n```\n\nBy 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.\n\n### NuGet\n\nThe library is available on NuGet packetmanager.\n\nhttps://www.nuget.org/packages/WART-Core/\n\n### Contributing\nThank you for considering to help out with the source code!\nIf you'd like to contribute, please fork, fix, commit and send a pull request for the maintainers to review and merge into the main code base.\n\n**Getting started with Git and GitHub**\n\n * [Setting up Git](https://docs.github.com/en/get-started/getting-started-with-git/set-up-git)\n * [Fork the repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo)\n * [Open an issue](https://github.com/engineering87/WART/issues) if you encounter a bug or have a suggestion for improvements/features\n\n### Licensee\nWART source code is available under MIT License, see license in the source.\n\n### Contact\nPlease contact at francesco.delre[at]protonmail.com for any details.\n","funding_links":["https://github.com/sponsors/engineering87"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fengineering87%2Fwart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fengineering87%2Fwart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fengineering87%2Fwart/lists"}