Feedback: Streaming #433
-
FeedbackI am looking for an example of streaming that does Server Sent Event. I would love to mock those in my current project. |
Beta Was this translation helpful? Give feedback.
Answered by
kettanaito
Nov 21, 2024
Replies: 1 comment 3 replies
-
Hi, @JasperV 👋 You can find a Server Sent Events example in here: https://alexocallaghan.com/mock-sse-with-msw. For posterity, here's the usage example: import { http, HttpResponse } from "msw";
const encoder = new TextEncoder();
const handler = http.get('http://example.com/stream', () => {
const stream = new ReadableStream({
start(controller) {
controller.enqueue(
encoder(
`event:some-event\ndata:some data\n\n`
)
);
controller.close();
},
});
return new HttpResponse(stream, {
headers: {
"Content-Type": "text/event-stream",
}.
});
}); I am also working on the first-class support for SSE events in mswjs/msw#2299. It's already in a usable state. Let me know if you'd like to give it a try, I can do a preview release for you to install it in your project. |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
kettanaito
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, @JasperV 👋
You can find a Server Sent Events example in here: https://alexocallaghan.com/mock-sse-with-msw.
For posterity, here's the usage example:
I am also working on the first-class support for SSE events in mswjs/msw#2299. …