Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/capi/deps/std/http.ts>ServerSentEvent

[WIP] A framework for crafting interactions with Substrate chains
Latest
class ServerSentEvent
extends Event
import { ServerSentEvent } from "https://deno.land/x/capi@v0.1.1-beta.1/deps/std/http.ts";

An event which contains information which will be sent to the remote connection and be made available in an EventSource as an event. A server creates new events and dispatches them on the target which will then be sent to a client.

See more about Server-sent events on MDN

Example

import {
  ServerSentEvent,
  ServerSentEventStreamTarget,
} from "https://deno.land/std@0.224.0/http/server_sent_event.ts";
import { serve } from "https://deno.land/std@0.224.0/http/server.ts";

await serve((request) => {
  const target = new ServerSentEventStreamTarget();
  const evt = new ServerSentEvent("message", {
    data: { hello: "world" },
    id: 1
  });
  target.dispatchEvent(evt);
  return target.asResponse();
}, { port: 8000 });

Constructors

new
ServerSentEvent(type: string, eventInit?: ServerSentEventInit)

Properties

readonly
data: string

The data associated with the event, which will be sent to the client and be made available in the EventSource.

readonly
id: number | undefined

The optional ID associated with the event that will be sent to the client and be made available in the EventSource.

Methods

toString(): string