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 compliance;
8pub mod config_status;
9pub mod crawl;
10pub mod discover;
11pub mod export;
12pub mod insights;
13pub mod market;
14pub mod portfolio;
15pub mod token_health;
16pub mod tx;
17
18use crate::web::AppState;
19use axum::Router;
20use std::sync::Arc;
21
22/// Registers all API routes under the `/api` prefix.
23pub fn routes(state: Arc<AppState>) -> Router<Arc<AppState>> {
24    Router::new()
25        .route("/address", axum::routing::post(address::handle))
26        .route("/tx", axum::routing::post(tx::handle))
27        .route("/insights", axum::routing::post(insights::handle))
28        .route("/crawl", axum::routing::post(crawl::handle))
29        .route("/discover", axum::routing::get(discover::handle))
30        .route("/token-health", axum::routing::post(token_health::handle))
31        .route("/market/summary", axum::routing::post(market::handle))
32        .route(
33            "/portfolio/list",
34            axum::routing::get(portfolio::handle_list),
35        )
36        .route("/portfolio/add", axum::routing::post(portfolio::handle_add))
37        .route("/export", axum::routing::post(export::handle))
38        .route(
39            "/compliance/risk",
40            axum::routing::post(compliance::handle_risk),
41        )
42        .route("/config/status", axum::routing::get(config_status::handle))
43        .route("/config", axum::routing::post(config_status::handle_save))
44        .with_state(state)
45}
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50    use crate::chains::DefaultClientFactory;
51    use crate::config::Config;
52
53    #[test]
54    fn test_routes_construction() {
55        let config = Config::default();
56        let factory = DefaultClientFactory {
57            chains_config: config.chains.clone(),
58        };
59        let state = Arc::new(AppState { config, factory });
60        let _router = routes(state);
61        // If this doesn't panic, routes are properly constructed
62    }
63}