torrust_index_backend/web/api/
mod.rs

1//! The Torrust Index Backend API.
2//!
3//! Currently, the API has only one version: `v1`.
4//!
5//! Refer to the [`v1`](crate::web::api::v1) module for more information.
6pub mod server;
7pub mod v1;
8
9use std::net::SocketAddr;
10use std::sync::Arc;
11
12use tokio::task::JoinHandle;
13
14use crate::common::AppData;
15use crate::web::api;
16
17/// API versions.
18pub enum Version {
19    V1,
20}
21
22/// The running API server.
23pub struct Running {
24    /// The socket address the API server is listening on.
25    pub socket_addr: SocketAddr,
26    /// The handle for the running API server.
27    pub api_server: Option<JoinHandle<Result<(), std::io::Error>>>,
28}
29
30#[must_use]
31#[derive(Debug)]
32pub struct ServerStartedMessage {
33    pub socket_addr: SocketAddr,
34}
35
36/// Starts the API server.
37#[must_use]
38pub async fn start(app_data: Arc<AppData>, net_ip: &str, net_port: u16, implementation: &Version) -> api::Running {
39    match implementation {
40        Version::V1 => server::start(app_data, net_ip, net_port).await,
41    }
42}