lonestone / nest-sdk-generator

A REST SDK generator for NestJS. Strictly type your frontend's API calls :rocket:
MIT License
92 stars 10 forks source link

Support Server-Sent Events #14

Open shiftgeist opened 1 year ago

shiftgeist commented 1 year ago

Nest Docu

Server-Sent Events (SSE) (since v7.5.0) are used as follows:

Nest controller

@Sse('sse')
sse(): Observable<MessageEvent> {
  return interval(1000).pipe(map((_) => ({ data: { hello: 'world' } })));
}

Client

const eventSource = new EventSource('/sse');
eventSource.onmessage = ({ data }) => {
  console.log('New message', JSON.parse(data));
};

Full Example from Nest: nestjs/nest/sample/28-sse