# Realtime API

URL: https://docs.folkways.io/docs/realtime-api

The API your apps and backend use to connect, publish, subscribe and manage topics, with every endpoint at a glance.

The Realtime API is what clients connect to. Your apps use it to publish and subscribe; your backend uses it to
publish, manage private topics, open direct messages and disconnect users. The [JavaScript SDK](/docs/js-sdk) speaks
it for you; this section is for other languages and for anyone who wants to know exactly what happens on the wire.

## Base URL [#base-url]

Each segment's **Connect** tab shows its Realtime URL, for example `https://realtime.folkways.net`. One host serves
every transport over TLS on port 443:

- WebSocket: `wss://realtime.folkways.net/v1/ws`
- HTTP: `https://realtime.folkways.net/v1/…`

Paths are versioned (`/v1`). The segment is never in a path or query string: it comes only from the token.

## Endpoints [#endpoints]

| Endpoint | Body | Auth | For |
| --- | --- | --- | --- |
| [`GET /v1/ws`](/docs/realtime-api/websocket) | Frames | Token in the first frame | Apps: live publish and subscribe |
| [`POST /v1/publish`](/docs/realtime-api/publish#post-v1publish) | Frames | `Authorization: Bearer <token>` | Publishing without a connection |
| [`POST /v1/poll`](/docs/realtime-api/poll) | Frames | `Authorization: Bearer <token>` | Receiving where WebSockets are blocked |
| [`POST /v1/token`](/docs/realtime-api/token) | JSON | `Authorization: Bearer <publishable key>` | Trading a publishable key for an anonymous token |
| [`POST /v1/dm/open`](/docs/realtime-api/dm-open) | JSON | Service token | Opening a DM or group room |
| [`POST /v1/members/add`](/docs/realtime-api/members) | JSON | Service token | Granting members ops on a private topic |
| [`POST /v1/members/set`](/docs/realtime-api/members) | JSON | Service token | Setting one member's ops |
| [`POST /v1/members/remove`](/docs/realtime-api/members) | JSON | Service token | Removing members |
| [`POST /v1/members/clear`](/docs/realtime-api/members) | JSON | Service token | Removing every member |
| [`POST /v1/members/list`](/docs/realtime-api/members) | JSON | Service token | Listing members |
| [`POST /v1/kick`](/docs/realtime-api/kick-and-revoke) | JSON | Service token | Disconnecting an identity |
| [`POST /v1/revoke`](/docs/realtime-api/kick-and-revoke) | JSON | Service token | Revoking one token |

## Two kinds of body [#two-kinds-of-body]

- **Frames.** The WebSocket, `/v1/publish` and `/v1/poll` carry binary **packets** of FlatBuffers **frames**:
  `Publish`, `Subscribe`, `Deliver` and so on. One schema covers all three. See [Payload format](/docs/realtime-api/payloads)
  and the [frame reference](/docs/realtime-api/frames).
- **JSON.** The token, DM, members, kick and revoke endpoints take and return JSON. Errors are
  `{ "code", "error", "message" }` with an HTTP status.

## Errors [#errors]

Every transport uses the same numbered [error codes](/docs/realtime-api/errors), such as `203 Forbidden` or
`300 RateLimited`. On a WebSocket they arrive as frames; over HTTP they also set the status code.

## Browsers and CORS [#browsers-and-cors]

`/v1/publish`, `/v1/poll` and `/v1/token` accept requests from any origin, with no cookies. The backend endpoints
(DMs, members, kick, revoke) don't allow browsers at all: they need service tokens, which never belong in an app.
WebSockets need no CORS.

## Building a client [#building-a-client]

A client in a new language needs:

1. FlatBuffers bindings generated from the [protocol schema](/docs/realtime-api/payloads#the-schema);
2. a token, from your backend or a publishable key;
3. the [WebSocket lifecycle](/docs/realtime-api/websocket): `Hello`, pings, token refresh, reconnects;
4. [subscribing with cursors](/docs/realtime-api/subscribe), and saving the last processed cursor per topic.

[Build a client in another language](/docs/realtime-api/build-a-client) walks through a complete Python client, and
the [client checklist](/docs/realtime-api/websocket#client-checklist) lists what a production client must do.
