Builds on counter-http by adding a "I'm feeling lucky"
button that adjusts the counter by a random amount between -5 and 5. The random
number generation is handled by
middleware — Rust code that intercepts
effects before they reach the shell.
The shared directory adds a custom
Random capability on top of the HTTP counter.
This demonstrates:
- Defining a custom
Operation(request/response types) for the middleware - Implementing
EffectMiddlewareto handle the operation in Rust - Wiring middleware into the core with
.handle_effects_using() - Narrowing the
Effectenum with.map_effect()so the shell never seesRandomeffects
This example has two FFI bridges that wire up the core differently:
- Native (uniffi) — The
RngMiddlewareinterceptsRandomeffects and handles them entirely in Rust. The shell never sees them. - Web (wasm_bindgen) — Middleware can't run in wasm (it uses
std::thread::spawn), soRandomeffects pass through to the shell, which handles them in JavaScript. This demonstrates the app working, but not the middleware feature itself.
- SwiftUI (iOS/macOS) —
apple/ - Android/Kotlin —
android/ - Leptos —
web-leptos/ - NextJS —
web-nextjs/
- Choose a shell you're interested in, i.e.
appleorandroid. - In the shell's directory, run
just doctorto make sure you have the right tools installed - Run
just devto generate code and build that shell - For
appleandandroidshells, open the IDE. For others, runjust servein the shell directory.