beet_router
beet_router is the semantic layer between an application and the interfaces it speaks through. A router is an entity hierarchy: each route is a child carrying a path pattern and an [Action]. A request arrives, whatever its transport, and is matched against the tree and dispatched to the action that fits.
Because the routes know nothing about where a request came from, one set of routes serves a command line, an HTTP server and an interactive prompt at the same time. An entry declares every IO layer it can speak through (CliServer, HttpServer, ReplServer, ...) and --server picks which of them act; the routes do not change.
use beet::prelude::*;
fn setup(mut commands: Commands) {
commands.spawn((
// declare the IO layers; `--server` picks which of them act
(CliServer::default(), ReplServer {
default_boot: false,
..default()
}),
CallOnReady::on_spawn(),
// the dispatch host is a child: route lookup plus the built-in app
// routes, wrapping the user routes declared as its own children
children![(Router::with_defaults(), children![
route::exchange("", Action::<(), &str>::new_pure(|_| "hello world")),
route::exchange("about", Action::<(), &str>::new_pure(|_| "about")),
])],
));
}
Routing is where one set of routes serving many interfaces becomes concrete, and it does more than dispatch. It can generate routes from a file tree (codegen feature), render route output into beet_ui scene trees, export a static site, and run on no_std targets through an embedded route core. The website you are reading is one such router rendered to HTML.