Folkways Developers
Everything to build with Folkways
Docs, the JavaScript SDK, guides, reference and examples. Publish and subscribe to live events with stream, kv and signal; reconnects, replay and token refresh are handled for you.
@folkwaysio/realtime is published on npm for browsers, React Native, Node.js, Deno and Bun.
npm install @folkwaysio/realtimeimport { Folkways } from '@folkwaysio/realtime';
const client = await Folkways.connect({
authUrl: '/api/realtime-token',
});
const chat = client.topic('chat/lobby');
chat.subscribe((msg) => show(msg.data), { from: { last: 20 } });
await chat.publish('message', { text: 'Hello!' });Start here
Three steps take you from sign-up to a working connection.
Learn and build
- Identities and tokensShort-lived tokens signed by your backend.
- TopicsNames, rules, public and private topics, DMs.
- StreamOrdered events you can replay from a cursor.
- KVThe latest value per key, with lifetimes.
- SignalTyping, cursors and other short-lived values.
- PresenceWho is online, and who is in each topic.
- Delivery and orderingReceipts, cursors, gaps and idempotent retries.
- Issue tokens from your backendcreateToken and capabilities per topic.
- Topic rulesEvery setting, and pasting rules from code.
- Using it with ReactLive UIs with useSyncExternalStore.
- Reliable WebSocket appsReconnects, bounded queues, idempotent writes.
- Production checklistWhat to check before you go live.
Reference
Realtime APIEvery endpoint, with what it takes and returns.TransportsWebSocket, HTTP publish and long-polling.Payload formatPackets, frames, content types and the schema.Error codesEvery code, whether to retry, what it means.Platform APIRead workspaces, segments and usage with an API key.SDK client optionsEvery option, its default and meaning.
Common questions
- What is Folkways?
- Folkways is hosted real-time infrastructure. Your apps publish and subscribe to live events on topics, and the JavaScript SDK handles reconnects, replay and token refresh for you. How Folkways works
- Which platforms does the JavaScript SDK support?
- Browsers, React Native, Node.js, Deno and Bun. Install it with npm install @folkwaysio/realtime. It includes TypeScript declarations. Installation
- How do users authenticate?
- Your backend signs a short-lived token for each user with @folkwaysio/realtime/server; tokens live at most 15 minutes. The SDK asks your endpoint for a new token about a minute before the current one expires, without dropping subscriptions. Public pages can use a read-only publishable key instead. Identities and tokens
- What happens when the connection drops?
- The SDK reconnects on its own and queues publishes in the meantime. After reconnecting it resubscribes every topic from the last event you handled, then sends the queued publishes. Connection and reconnects
- When should I use stream, kv or signal?
- Use stream for ordered events you can replay, such as chat messages or AI tokens. Use kv for state: only the latest value per key is kept, and new subscribers get the current values first. Use signal for short-lived activity such as typing and cursors: signals are not stored, and each sender’s latest one expires after 5 seconds by default. Primitives
SDKs
- JavaScript / TypeScript
- Python · not yet available
- Go · not yet available
- Java / Kotlin · not yet available
- Swift · not yet available