Skip to main content

stratum_apps/monitoring/
routes.rs

1//! Canonical path constants and helpers for the monitoring HTTP API.
2//!
3//! Centralising these constants here lets the server router, in-crate unit
4//! tests, and downstream integration tests all reference the same strings.
5//! New endpoints must be added here so every consumer stays in sync.
6
7// ── Top-level paths ─────────────────────────────────────────────────
8
9pub const ROOT: &str = "/";
10pub const METRICS: &str = "/metrics";
11pub const SWAGGER_UI: &str = "/swagger-ui";
12pub const OPENAPI_SPEC: &str = "/api-docs/openapi.json";
13
14// ── /api/v1 prefix ──────────────────────────────────────────────────
15
16/// Common prefix for all versioned JSON API endpoints.
17pub const API_V1_PREFIX: &str = "/api/v1";
18
19/// Path segments relative to [`API_V1_PREFIX`], intended for use with
20/// `axum::Router::nest(API_V1_PREFIX, ...)`. Kept in their own module so the
21/// namespace (not a name prefix) signals that these strings are *not* full
22/// URL paths and are not interchangeable with the full-path constants below.
23pub mod segments {
24    pub const HEALTH: &str = "/health";
25    pub const GLOBAL: &str = "/global";
26    pub const SERVER: &str = "/server";
27    pub const SERVER_CHANNELS: &str = "/server/channels";
28    pub const CLIENTS: &str = "/clients";
29    pub const CLIENT_BY_ID: &str = "/clients/{client_id}";
30    pub const CLIENT_CHANNELS: &str = "/clients/{client_id}/channels";
31    pub const SV1_CLIENTS: &str = "/sv1/clients";
32    pub const SV1_CLIENT_BY_ID: &str = "/sv1/clients/{client_id}";
33}
34
35// ── Full paths under /api/v1 ────────────────────────────────────────
36
37pub const HEALTH: &str = "/api/v1/health";
38pub const GLOBAL: &str = "/api/v1/global";
39pub const SERVER: &str = "/api/v1/server";
40pub const SERVER_CHANNELS: &str = "/api/v1/server/channels";
41pub const CLIENTS: &str = "/api/v1/clients";
42pub const SV1_CLIENTS: &str = "/api/v1/sv1/clients";
43
44// Templated full paths (with `{client_id}` placeholder) — used in API
45// listings exposed by the root endpoint and anywhere a human-readable
46// path-with-placeholder is needed.
47pub const CLIENT_BY_ID_PATTERN: &str = "/api/v1/clients/{client_id}";
48pub const CLIENT_CHANNELS_PATTERN: &str = "/api/v1/clients/{client_id}/channels";
49pub const SV1_CLIENT_BY_ID_PATTERN: &str = "/api/v1/sv1/clients/{client_id}";
50
51/// Path for `/api/v1/clients/{id}` with the id substituted in.
52pub fn client_by_id(id: usize) -> String {
53    format!("{CLIENTS}/{id}")
54}
55
56/// Path for `/api/v1/clients/{id}/channels` with the id substituted in.
57pub fn client_channels(id: usize) -> String {
58    format!("{CLIENTS}/{id}/channels")
59}
60
61/// Path for `/api/v1/sv1/clients/{id}` with the id substituted in.
62pub fn sv1_client_by_id(id: usize) -> String {
63    format!("{SV1_CLIENTS}/{id}")
64}