Skip to main content

Controller-first Server-Sent Events projection with one typed result model for Koan web applications and framework transports.

Total Downloads
5.0K
4,950
Published
Sep 13, 2026
1mo ago

Get Started

dotnet add package Sylin.Koan.Web.Sse --version 1.0.58
ProductVersions
.NET
net10.0

README

Sylin.Koan.Web.Sse

Return typed Server-Sent Events from a controller with one expression.

Install

dotnet add package Sylin.Koan.Web.Sse

The package composes through the application's existing AddKoan() call.

Smallest meaningful result

[ApiController]
[Route("api/orders")]
public sealed class OrdersController : ControllerBase
{
    [HttpGet("updates")]
    public IActionResult Updates(CancellationToken cancellationToken)
        => Sse.Stream(OrderUpdates.Read(cancellationToken));
}

Sse.Stream(...) accepts any IAsyncEnumerable<T>:

  • typed values become compact Newtonsoft JSON;
  • strings remain unquoted text; and
  • SseEnvelope values preserve explicit event name, id, retry, comment, and unnamed control frames.

The returned SseResult implements both MVC IActionResult and ASP.NET IResult, so Koan transports and application controllers use the same wire engine without two helper vocabularies.

Configure only the fallback event name when needed:

{
  "Koan": {
    "Web": {
      "Sse": {
        "DefaultEvent": "message"
      }
    }
  }
}

Guarantees and boundaries

  • Responses use text/event-stream, add ordinary proxy buffering/caching guidance when absent, flush every frame, and stop on request cancellation. Existing stronger cache or application-owned transport directives survive.
  • Typed and text values receive the explicit Sse.Stream(..., eventName) value or configured default. An explicit envelope remains unnamed unless the caller supplies eventName.
  • An envelope with empty data plus a comment, retry, or id is a control frame. It emits only those control fields, even when the stream has a fallback event name; comment-only heartbeats are exactly : text plus the blank frame terminator.
  • Empty text chunks are skipped; multiline data is emitted as valid repeated data: lines.
  • The package does not promise delivery, replay, resume storage, heartbeat generation, backpressure persistence, authentication, or proxy-specific buffering behavior. Compose those concerns at their owning transport or host.

See TECHNICAL.md for projection and execution ownership.

Downloads by Version

Similar & Alternative Packages

Hand-picked matching NuGet libraries based on tags & ecosystem

Depended On By

Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.