Prefer consolidating common configuration and parameters in API constructors or base methods rather than requiring multiple method calls, complex parameter passing, or external configuration loading. This reduces API surface area and makes interfaces easier to use for consumers.
When designing APIs, favor approaches that:
Example of preferred approach:
// Instead of separate methods for each model type
pub async fn complete_with_model(&self, model: Option<String>) -> Result<Message> {
let model = model.unwrap_or_else(|| self.default_model());
// implementation
}
// Instead of requiring multiple setup calls
pub fn new(api_key: String) -> Result<Self> {
let mut client = ApiClient::new(host, auth)?;
// Load common config automatically
if let Some(tls_config) = TlsConfig::from_config()? {
client = client.with_tls_config(tls_config)?;
}
Ok(Self { client })
}
// Instead of string-based parameters, use direct types
pub fn create_tool(schema: serde_json::Value) -> Tool {
// Use schema directly instead of requiring JSON string
}
This approach reduces the cognitive load on API consumers and prevents the need to understand complex setup sequences or parameter serialization formats.
Enter the URL of a public GitHub repository