Skip to content

Server-sent events client implementation #372

@MykhailoMatiiasevychKlarna

Description

Server-sent events client implementation

Purpose

I want to bump with the community and understand if this feature would be interesting and useful in scope of mappersmith.

Docs

https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events

Use case

Even though the technology is well known and supported by browsers it seems to be rarely used in backend-2-backend communication.
With the boom of chatGPT this become a case as it is supporting streaming using Server-sent events: https://platform.openai.com/docs/api-reference/chat/create

Suggested implementation

Currently payload is available as a text when the request is completed.
My implementation suggestion would be to pass eventEmitter as a parameter to resource method and emit events from inside mappersmith on every new chunk of data.

import { EventEmitter } from 'node:events';
const events = new EventEmitter();

events.on('data', (data) => {
  console.log(data);
})

client.Resource.method({ eventEmitter: events })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions