torrust_index/web/api/
mod.rs

1//! The Torrust Index API.
2//!
3//! Currently, the API has only one version: `v1`.
4//!
5//! Refer to:
6//!
7//! - [`client::v1`]) module for more information about the API client.
8//! - [`server::v1`]) module for more information about the API server.
9pub mod client;
10pub mod server;
11
12use std::net::SocketAddr;
13use std::sync::Arc;
14
15use tokio::task::JoinHandle;
16
17use self::server::signals::Halted;
18use crate::common::AppData;
19use crate::config::Tsl;
20use crate::web::api;
21
22/// API versions.
23pub enum Version {
24    V1,
25}
26
27/// The running API server.
28pub struct Running {
29    /// The socket address the API server is listening on.
30    pub socket_addr: SocketAddr,
31    /// The channel sender to send halt signal to the server.
32    pub halt_task: tokio::sync::oneshot::Sender<Halted>,
33    /// The handle for the running API server.
34    pub task: JoinHandle<Result<(), std::io::Error>>,
35}
36
37/// Starts the API server.
38#[must_use]
39pub async fn start(
40    app_data: Arc<AppData>,
41    config_bind_address: SocketAddr,
42    opt_tsl: Option<Tsl>,
43    implementation: &Version,
44) -> api::Running {
45    match implementation {
46        Version::V1 => server::start(app_data, config_bind_address, opt_tsl).await,
47    }
48}