Function feattle_ui::axum_router

source ·
pub fn axum_router<F>(admin_panel: Arc<AdminPanel<F>>) -> Router<()>
where F: Feattles + Sync + Send + 'static,
Expand description

Return an axum router that serves the admin panel.

To use it, make sure to activate the cargo feature "axum" in your Cargo.toml.

The router will answer to the web UI under “/” and a JSON API under “/api/v1/” (see more at v1):

  • GET /api/v1/feattles
  • GET /api/v1/feattle/{key}
  • POST /api/v1/feattle/{key}


use std::future::IntoFuture;
use feattle_ui::{AdminPanel, axum_router};
use feattle_core::{feattles, Feattles};
use feattle_core::persist::NoPersistence;
use std::sync::Arc;

use tokio::net::TcpListener;

feattles! {
    struct MyToggles { a: bool, b: i32 }

// `NoPersistence` here is just a mock for the sake of the example
let my_toggles = Arc::new(MyToggles::new(Arc::new(NoPersistence)));
let admin_panel = Arc::new(AdminPanel::new(my_toggles, "Project Panda - DEV".to_owned()));

let router = axum_router(admin_panel);

let listener = TcpListener::bind(("", 3031)).await?;
tokio::spawn(axum::serve(listener, router.into_make_service()).into_future());