flaron-sdk
The official Rust SDK for building flares - WebAssembly functions that run on the Flaron CDN edge.
A flare is a small Wasm module deployed to every Flaron edge node worldwide. The host runtime invokes your handle_request export when a request lands at the nearest edge, your code runs in a sandboxed runtime with single-digit-millisecond cold starts, and the response is shipped back to the client without ever touching your origin.
use ;
handle_request!;
Installation
Add the SDK to your Cargo.toml:
[]
= "my-flare"
= "0.1.0"
= "2021"
[]
= ["cdylib"]
[]
= "0.1"
[]
= "z"
= true
= 1
= "abort"
= true
You will need the wasm32-unknown-unknown target installed:
Then build your flare:
The resulting target/wasm32-unknown-unknown/release/my_flare.wasm is what you upload to Flaron.
Quick start: HTTP echo flare
Create a new library crate:
Set the crate type to cdylib and add the SDK as in the Installation section above.
Replace src/lib.rs with:
use ;
handle_request!;
The handle_request! macro takes the name of your handler function and
expands to the alloc and handle_request exports the host runtime
requires. The macro resets the bump arena on every invocation and converts
your returned [FlareAction] into the i64 the host expects.
For WebSocket flares the equivalent macro is ws_handlers!:
use ;
ws_handlers!;
Pass the three handler names in open, message, close order. The macro
exports ws_open / ws_message / ws_close and resets the arena before
each call.
Use handle_request! or ws_handlers! per crate, never both - they
each define the alloc export the host runtime requires.
Build and deploy:
Curl the edge to see it run:
Features
The SDK exposes the full Flaron edge runtime through ergonomic Rust modules. Every operation runs in the host's native code path - no allocator, no async runtime, no crypto crate gets pulled into your .wasm.
Request and response
request- read inboundmethod,url, individualheader(name), and requestbodybytes.response- writeset_status,set_header(k, v),set_body(bytes),set_body_str(s).
Outbound HTTP - beam
Make HTTP calls from the edge to your origin or third-party APIs. Supports method, headers, body, and returns status, headers, and response body.
use ;
let resp = fetch?;
Edge KV stores
spark- per-site key/value with TTL, persisted to local disk on each edge node. Best for caching, session state, and rate-limit counters local to one edge.plasma- cross-edge CRDT key/value replicated via gossip. Best for state that must be visible from any edge: PN counters, presence, leaderboards, feature flags.
use ;
set?; // expires in 1 hour
let session = get;
increment; // CRDT, gossiped to all edges
Secrets - secrets
Read domain-scoped secrets that have been allowlisted for this flare. Secret values are gated by the flare's allowed_secrets config - anything not on the list returns None.
let api_key = get;
For HMAC and JWT signing, prefer the crypto helpers - they reference secrets by name without ever exposing the raw bytes to Wasm.
Cryptography - crypto
Hash, HMAC, AES-GCM encrypt/decrypt, JWT signing, and CSPRNG random bytes. All operations run in the host's native crypto stack so they are constant-time and dramatically faster than a pure-Wasm crypto build.
use HashMap;
use crypto;
let digest = hash;
let mac = hmac;
let mut claims = new;
claims.insert;
let jwt = sign_jwt;
let entropy = random_bytes?;
Encoding helpers - encoding
Zero-dep wrappers for base64, hex, and URL percent-encoding. Calling the host avoids pulling encoding crates into your Wasm binary.
ID generators - id
UUID v4, UUID v7 (time-ordered), ULID, KSUID, Nanoid, and Snowflake. All generated by the host's native crypto + clock so IDs are collision-resistant across edges with no entropy crate in your binary.
Time - time
Timestamps in any format you need: unix seconds, milliseconds, nanoseconds, RFC3339, HTTP date, ISO8601.
Logging - logging
info, warn, and error surfaced via the edge node's structured log stream - visible in the Flaron dashboard and forwarded to your log sink.
WebSockets - ws
Receive open / message / close events and send / close from the flare. The same module exposes event_type, event_data, event_text, and close_code for the inbound side.
Memory model
Each invocation starts with a fresh 256 KiB bump arena. The host writes return data into the arena via your exported alloc function. The handle_request! and ws_handlers! macros include the alloc export and reset the arena on every invocation - you never need to free anything.
This is why most SDK functions return owned String or Vec<u8> values: they are read out of the arena and copied into the linear-memory heap before the arena is reset on the next call.
If you need to define the host exports yourself (custom handle_request shape, multiple entry points, etc.) call flaron_sdk::export_alloc!() and flaron_sdk::reset_arena() directly instead of using the macros.
Examples
The examples/ directory contains seven complete flares you can build today:
| Example | What it shows |
|---|---|
hello |
Minimal HTTP responder |
spark-counter |
Per-edge KV with TTL |
plasma-counter |
Cross-edge CRDT counter |
secret-jwt |
Sign a JWT with a domain secret |
websocket-echo |
WebSocket open / message / close |
beam-fetch |
Outbound HTTP from the edge |
edge-ops |
Crypto, encoding, ID, and timestamp showcase |
Build them all from the workspace root:
Each example is a workspace member - its .wasm lands in target/wasm32-unknown-unknown/release/<example_name>.wasm.
Documentation
- Flaron docs: https://flaron.dev
- Repository: https://github.com/flaron-cdn/flare-rs
License
MIT - see LICENSE.