terminal_jarvis/api/api_base.rs
1#![allow(dead_code)]
2
3//! Base API configuration and URL management
4//!
5//! **STATUS: FUTURE-USE MODULE** - Foundation for remote service integration
6//!
7//! This module provides foundational API configuration that will be activated when
8//! Terminal Jarvis connects to remote services for tool discovery and metadata.
9//!
10//! # Purpose
11//!
12//! The [`ApiBase`] struct centralizes all HTTP client configuration, including:
13//! - Base URL management for different environments
14//! - Timeout and retry logic configuration
15//! - Connection pooling settings
16//! - Authentication endpoint configuration
17//!
18//! # Future Usage Example
19//!
20//! ```rust,ignore
21//! let api_config = ApiBase::new()
22//! .with_base_url("https://api.terminal-jarvis.dev")
23//! .with_timeout(60)
24//! .with_max_retries(5);
25//!
26//! let client = ApiClient::with_config(api_config);
27//! ```
28
29/// Default base URL for Terminal Jarvis API services
30///
31/// This constant ensures consistency across all API-related modules and
32/// provides a single source of truth for the base URL configuration.
33const DEFAULT_API_BASE_URL: &str = "https://api.terminal-jarvis.dev";
34
35/// Base configuration for API clients
36///
37/// Centralizes HTTP client settings including base URL, timeouts, and retry logic.
38/// Designed to support different environments (dev, staging, prod) and provide
39/// consistent configuration across all API operations.
40///
41/// # Fields
42///
43/// * `base_url` - The root URL for all API endpoints
44/// * `timeout_seconds` - Request timeout in seconds
45/// * `max_retries` - Maximum number of retry attempts for failed requests
46pub struct ApiBase {
47 pub base_url: String,
48 pub timeout_seconds: u64,
49 pub max_retries: u32,
50}
51
52impl Default for ApiBase {
53 fn default() -> Self {
54 Self {
55 base_url: DEFAULT_API_BASE_URL.to_string(),
56 timeout_seconds: 30,
57 max_retries: 3,
58 }
59 }
60}
61
62impl ApiBase {
63 /// Creates a new ApiBase with default configuration
64 ///
65 /// # Returns
66 ///
67 /// An ApiBase instance configured with:
68 /// - Base URL: `https://api.terminal-jarvis.dev`
69 /// - Timeout: 30 seconds
70 /// - Max retries: 3 attempts
71 pub fn new() -> Self {
72 Self::default()
73 }
74
75 /// Creates ApiBase with custom base URL
76 ///
77 /// # Arguments
78 ///
79 /// * `base_url` - The base URL for API requests
80 ///
81 /// # Returns
82 ///
83 /// An ApiBase instance with the specified base URL and default settings
84 #[allow(dead_code)]
85 pub fn with_base_url(mut self, base_url: &str) -> Self {
86 self.base_url = base_url.to_string();
87 self
88 }
89
90 /// Sets request timeout in seconds
91 ///
92 /// # Arguments
93 ///
94 /// * `timeout_seconds` - Timeout duration in seconds
95 ///
96 /// # Returns
97 ///
98 /// Self for method chaining
99 #[allow(dead_code)]
100 pub fn with_timeout(mut self, timeout_seconds: u64) -> Self {
101 self.timeout_seconds = timeout_seconds;
102 self
103 }
104
105 /// Sets maximum retry attempts
106 ///
107 /// # Arguments
108 ///
109 /// * `max_retries` - Maximum number of retry attempts
110 ///
111 /// # Returns
112 ///
113 /// Self for method chaining
114 #[allow(dead_code)]
115 pub fn with_max_retries(mut self, max_retries: u32) -> Self {
116 self.max_retries = max_retries;
117 self
118 }
119
120 /// Get the full URL for an endpoint
121 pub fn endpoint_url(&self, path: &str) -> String {
122 format!(
123 "{}/{}",
124 self.base_url.trim_end_matches('/'),
125 path.trim_start_matches('/')
126 )
127 }
128}
129
130/// API route definitions
131pub mod routes {
132 pub const TOOLS: &str = "/api/v1/tools";
133 pub const TOOL_INFO: &str = "/api/v1/tools/{tool}";
134 pub const TOOL_VERSIONS: &str = "/api/v1/tools/{tool}/versions";
135 pub const TEMPLATES: &str = "/api/v1/templates";
136 pub const TEMPLATE_INFO: &str = "/api/v1/templates/{template}";
137}