Skip to content

Repository files navigation

Twilic Examples

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.

Prerequisites

  • Node.js 24+
  • Bun (recommended)

Setup

bun install

Examples

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

API response (HTTP)

# terminal 1
bun run example:api-response

# terminal 2
bun run example:api-response:client

HTTP adapter round-trip

Express / 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

WebSocket session

# size comparison (recommended first)
bun run example:websocket:simulate

# live stream
bun run example:websocket          # terminal 1
bun run example:websocket:client   # terminal 2

CLI examples

bun run example:batch-records
bun run example:telemetry
bun run example:logs
bun run example:cache-payload

Goals

  • 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

When Twilic Fits Well

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.

Related resources

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Example projects showing how to use Twilic for APIs, batches, sessions, telemetry, logs, and compact binary payloads.

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages