Last active
November 24, 2025 00:40
-
-
Save AnthonyGiretti/243f8a4911704afb5a8306851c028b76 to your computer and use it in GitHub Desktop.
Server-sent event in ASP.NET Core 10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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