Official example projects and real-world use cases for Twilic.
Twilic Examples is a collection of practical examples that show how Twilic can be used in real applications. The goal of this repository is to make Twilic easier to understand, evaluate, and adopt by demonstrating concrete use cases instead of only providing the specification or library API.
Twilic is especially useful when data contains repeated structures, repeated strings, homogeneous records, batched payloads, or session-based updates. These examples show how Twilic can be used as a compact binary representation for APIs, WebSocket messages, telemetry data, logs, cache payloads, and other structured data.
- Node.js 24+
- Bun (recommended)
bun install| Example | Profile | Command |
|---|---|---|
| api-response | Stateless Batch | bun run example:api-response |
| http-roundtrip | Stateless Dynamic | bun run example:http-roundtrip |
| websocket-session | Stateful | bun run example:websocket:simulate |
| batch-records | Batch | bun run example:batch-records |
| telemetry | Batch (col_batch) |
bun run example:telemetry |
| logs | Dynamic + Batch | bun run example:logs |
| cache-payload | Dynamic (stateless) | bun run example:cache-payload |
# terminal 1
bun run example:api-response
# terminal 2
bun run example:api-response:clientExpress / Hono / Fastify server with fetch or Axios client. Both sides use application/vnd.twilic.
# terminal 1 — pick one
bun run example:http-roundtrip
bun run example:http-roundtrip:hono
bun run example:http-roundtrip:fastify
# terminal 2 — pick one
bun run example:http-roundtrip:client
bun run example:http-roundtrip:axios# size comparison (recommended first)
bun run example:websocket:simulate
# live stream
bun run example:websocket # terminal 1
bun run example:websocket:client # terminal 2bun run example:batch-records
bun run example:telemetry
bun run example:logs
bun run example:cache-payload- Show practical use cases for Twilic
- Compare Twilic with JSON and MessagePack where useful
- Provide small examples that are easy to run and modify
- Demonstrate Twilic features such as batch encoding, compact payloads, and session patches
- Help developers decide when Twilic is a good fit
Twilic is designed to work well with data that has repeated patterns. It can be a good fit when many messages share the same object shape, when the same strings appear repeatedly, when records are sent in batches, or when only small changes need to be sent after the first message.
Twilic is not intended to replace every serialization format in every situation. These examples are designed to make the trade-offs visible and help developers choose Twilic for the right use cases.
- Cookbook — practical patterns
- Playground — interactive size comparison
- Benchmark — encode/decode throughput
- @twilic/core — JavaScript SDK
This project is licensed under the MIT License - see the LICENSE file for details.