Skip to main content

HttpConnector

Plain REST polling adapter. The simplest deployment — no WebSockets, no SSE, no SignalR. The connector POSTs outgoing messages and GETs new ones on a fixed interval.

import { HttpConnector } from "@chativa/connector-http";

ConnectorRegistry.register(
new HttpConnector({
url: "https://api.example.com/chat",
pollInterval: 2000,
headers: { Authorization: `Bearer ${token}` },
})
);
chatStore.getState().setConnector("http");

Options

Schema: schemas/connectors/http.schema.json.

FieldDefaultDescription
url (required)Base URL of the chat REST API.
pollInterval2000Polling interval in milliseconds.
headers{}Headers sent with every request.
maxErrors5After this many consecutive fetch errors, stop polling and report disconnect.

Wire format

EndpointMethodRequestResponse
/messages?cursor=...GET{ messages: IncomingMessage[], cursor?: string }
/messagesPOSTOutgoingMessage200 / 201, body ignored
/surveyPOSTSurveyPayload200 / 201, body ignored
/history?cursor=...GET (optional)HistoryResult

The connector tracks the last seen cursor in memory (_cursor) and keeps requesting ?cursor=... to fetch only new messages.

When to use it

Choose HTTP polling when:

  • Your infra already exposes REST and you don't want to deploy a WebSocket layer.
  • Latency tolerance is ≥ 1–2 seconds.
  • You need predictable behaviour through corporate proxies / firewalls.

Pick a streaming connector (SSE, WebSocket, SignalR, or DirectLine) when sub-second latency or typing indicators matter.