File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -415,6 +415,27 @@ const app = new Elysia()
415
415
416
416
This this example, we may stream a response by using ` yield ` keyword.
417
417
418
+ ## Server Sent Events (SSE)
419
+ Elysia supports [Server Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events) by providing a ` sse` utility function.
420
+
421
+ ` ` ` typescript twoslash
422
+ import { Elysia , sse } from ' elysia'
423
+
424
+ new Elysia ()
425
+ .get (' /sse' , function * () {
426
+ yield sse (' hello world' )
427
+ yield sse ({
428
+ event : ' message' ,
429
+ data: {
430
+ message: ' This is a message' ,
431
+ timestamp: new Date ().toISOString ()
432
+ },
433
+ })
434
+ })
435
+ ` ` `
436
+
437
+ When a value is wrapped in ` sse` , Elysia will automatically set the response headers to ` text/ event - stream` and format the data as an SSE event.
438
+
418
439
### Set headers
419
440
Elysia will defers returning response headers until the first chunk is yielded.
420
441
You can’t perform that action at this time.
0 commit comments