Skip to main content

scope/web/api/
mod.rs

1//! # Web API Handlers
2//!
3//! REST API endpoints mirroring CLI commands. Each handler accepts JSON
4//! request bodies matching CLI argument structures and returns JSON responses.
5
6pub mod address;
7pub mod address_book;
8pub mod compliance;
9pub mod config_status;
10pub mod crawl;
11pub mod discover;
12pub mod exchange;
13pub mod export;
14pub mod insights;
15pub mod market;
16pub mod token_health;
17pub mod tx;
18pub mod venues;
19
20use crate::web::AppState;
21use axum::Router;
22use std::sync::Arc;
23
24/// Registers all API routes under the `/api` prefix.
25pub fn routes(state: Arc<AppState>) -> Router<Arc<AppState>> {
26    Router::new()
27        .route("/address", axum::routing::post(address::handle))
28        .route("/tx", axum::routing::post(tx::handle))
29        .route("/insights", axum::routing::post(insights::handle))
30        .route("/crawl", axum::routing::post(crawl::handle))
31        .route("/discover", axum::routing::get(discover::handle))
32        .route("/token-health", axum::routing::post(token_health::handle))
33        .route("/market/summary", axum::routing::post(market::handle))
34        .route(
35            "/address-book/list",
36            axum::routing::get(address_book::handle_list),
37        )
38        .route(
39            "/address-book/add",
40            axum::routing::post(address_book::handle_add),
41        )
42        .route("/export", axum::routing::post(export::handle))
43        .route(
44            "/compliance/risk",
45            axum::routing::post(compliance::handle_risk),
46        )
47        .route("/config/status", axum::routing::get(config_status::handle))
48        .route("/config", axum::routing::post(config_status::handle_save))
49        .route("/venues", axum::routing::get(venues::handle))
50        .route("/exchange/snapshot", axum::routing::post(exchange::handle))
51        .route(
52            "/exchange/trades",
53            axum::routing::post(exchange::handle_trades),
54        )
55        .route("/exchange/ohlc", axum::routing::post(exchange::handle_ohlc))
56        .with_state(state)
57}
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62    use crate::chains::DefaultClientFactory;
63    use crate::config::Config;
64
65    #[test]
66    fn test_routes_construction() {
67        let config = Config::default();
68        let factory = DefaultClientFactory {
69            chains_config: config.chains.clone(),
70        };
71        let state = Arc::new(AppState { config, factory });
72        let _router = routes(state);
73        // If this doesn't panic, routes are properly constructed
74    }
75}