Skip to content

Instantly share code, notes, and snippets.

@AnthonyGiretti
Last active November 24, 2025 00:40
Show Gist options
  • Select an option

  • Save AnthonyGiretti/243f8a4911704afb5a8306851c028b76 to your computer and use it in GitHub Desktop.

Select an option

Save AnthonyGiretti/243f8a4911704afb5a8306851c028b76 to your computer and use it in GitHub Desktop.
Server-sent event in ASP.NET Core 10
var app = builder.Build();
app.UseCors();
// SSE endpoint in ASP.NET Core 10
app.MapGet("/countries/stream", (CountryService service, CancellationToken ct) =>
{
var stream = service.StreamCountries(ct);
// Each Country will be sent as an SSE event named "country"
// Content-Type: text/event-stream
// Fits for unidirectional push, where Websockets is good for both
// Replace data polling
return TypedResults.ServerSentEvents(stream, eventType: "country");
});
app.Run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment