E5C4 HubDocs/src/HubDocs at main · mberrishdev/HubDocs · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History

README.md

HubDocs

A Swagger-like UI for exploring and documenting SignalR hubs in ASP.NET Core applications.

Features

  • 🔍 Automatic discovery of SignalR hubs and strongly-typed client interfaces
  • 📝 Method documentation with parameters and return types
  • 🎨 Beautiful Swagger-inspired dark theme UI
  • 🔌 Easy integration with minimal configuration
  • 📡 Live view of client method invocations from server (via strongly-typed interfaces)

🎥 Live Demo

HubDocs Demo

The HubDocs UI in action — exploring hubs, invoking methods, and seeing real-time client logs.


🖼️ Screenshots

HubDocs Screenshot 1
📌 SignalR Hub list

HubDocs Screenshot 2
🔍 Interactive method parameter inputs with \"Try it\" support

HubDocs Screenshot 4
📡 Live client method logging with JSON preview

HubDocs Screenshot 3
📭 No methods found — HubDocs will show helpful instructions if a hub is registered without a route.

Installation

dotnet add package HubDocs

Quick Start

  1. Mark your SignalR hubs with the [HubDocs] attribute:
using HubDocs;

[HubDocs]
public class ChatHub : Hub<IChatClient>
{
    // ... your hub methods
}
  1. Register your hubs and add HubDocs in your ASP.NET Core application:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSignalR();

var app = builder.Build();

// Register your SignalR hubs
app.MapHub<ChatHub>("/hubs/chat");

// Add HubDocs - discovers hubs with [HubDocs] attribute
app.AddHubDocs();

app.Run();
  1. Access the HubDocs UI at /hubdocs/index.html or /hubdocs/ in your browser.

Example

public interface IChatClient
{
    Task ReceiveMessage(string user, string message);
    Task Connected(string connectionId);
}

[HubDocs]  // Mark for documentation
public class ChatHub : Hub<IChatClient>
{
    public async Task SendMessage(string user, string message)
    {
        await Clients.All.ReceiveMessage(user, message);
    }

    public override async Task OnConnectedAsync()
    {
        await Clients.Caller.Connected(Context.ConnectionId);
    }
}

Note: To fully leverage HubDocs, your hubs should implement Hub<T> with a strongly-typed client interface (T) that defines the client-callable methods. HubDocs will automatically extract and render both hub and client method metadata in the UI.

HubDocs will automatically discover and display:

  • Hub name and full type name
  • Route where the hub is registered
  • All public methods with parameters and return types
  • Client methods from strongly-typed interface
  • Interactive UI for exploring the hub

Configuration

Basic Configuration

// Register hubs with MapHub
app.MapHub<ChatHub>("/hubs/chat");

// Add HubDocs
app.AddHubDocs();

Custom Assemblies

Scan specific assemblies for hubs:

app.AddHubDocs(typeof(ExternalHub).Assembly);

Opt-in with Attribute

Only hubs marked with [HubDocs] attribute are documented. This provides control over which hubs appear in the UI.

Links

0