Examples

Native transport examples

Build and run the upstream HTTP, WebSocket, SSE, streams, MessageChannel and TCP exchanges.

Build a working exchange, then inspect it

The native examples create their own local resources, exchange data, assert the result and close resources before exit. The pages below include complete source and build files, commands, expected output and an explanation of each operation. They use the same pinned revision as the API reference.

Set up once

Requires Java 21+, Clojure CLI and the selected JavaScript runtime.

git clone https://github.com/OUTCASTGEEK-TECH/fast-twitch.git
cd fast-twitch
git checkout a4eb73f96836d034c7a24fe09dc7d51e4c581f64
cd examples/07-native-transports

The example's deps.edn uses the framework in the cloned repository and pins its official ClojureScript compiler. The build task chooses a namespace and creates target/<mode>.cjs. It does not require copying an unexplained handler into a new project. Programs use ephemeral ports where a listener is required.

Choose a walkthrough

Walkthrough Build Run What you learn
HTTP forwarding clojure -M:build http node target/http.cjs Preserve a native body while editing status/headers, then collect text
WebSocket echo clojure -M:build websocket bun target/websocket.cjs or deno run -A target/websocket.cjs Ring upgrade, open readiness, callbacks and shutdown
SSE producers/consumers clojure -M:build sse node target/sse.cjs or deno run -A target/sse.cjs Pull producer, Fetch consumer and named native EventSource events
Streams clojure -M:build streams node target/streams.cjs Abort, ownership, lock release and incremental UTF-8
MessageChannel clojure -M:build ports node target/ports.cjs JSON values, port event data and closing both handles
TCP clojure -M:build tcp-node node target/tcp-node.cjs Bounded reads, EOF-based replies and half-close
TCP on Bun clojure -M:build tcp-bun bun target/tcp-bun.cjs Same application protocol, Bun native adapter
TCP on Deno clojure -M:build tcp-deno deno run -A target/tcp-deno.cjs Same application protocol, Deno native adapter

Start with server applications instead

Hello World shows the smallest Fetch adapter application. Hiccup & Integrant adds rendered HTML and component configuration. Request destructuring explains every parameter representation. Uploads & static files adds multipart/native files. Todo sessions covers authentication, cookies, flash and CSRF. Celld and workerd show Fetch-only runtime entries and Vite builds.

Read the contract before changing the program

Use the native option reference for complete settings, callback arities, return values and limitations. Use the stream guide for ownership and cancellation. A native capability on one runtime does not imply another has it: Bun/Deno support server WebSocket upgrades; Node's adapter returns 501. Native EventSource is supplied by the Deno profile, while Fetch SSE works across the three server runtimes.

Each program's finally block is part of the example. Leaving a listener, source or port open can keep the process alive even when the exchange succeeded. TCP collection is EOF-based and has no framing; WebSocket and port reception is event-driven.

Source revision a4eb73f96836d034c7a24fe09dc7d51e4c581f64

Built with Fast-Twitch · Integrant · Datastar

Search documentation

Search pages and API symbols

Start hereWelcome to Fast-TwitchRing HTTP applications and configured native clients and transports in ClojureScript.Start hereGetting startedCompile and run your first Fast-Twitch server.Core conceptsRequest & responseUnderstand the maps at the center of a Fast-Twitch application.Core conceptsRoutingMatch URL patterns and compose handlers.Core conceptsMiddlewareWrap handlers with focused request and response behavior.GuidesHTML & IntegrantCompose a UI system with Integrant and render Hiccup.