1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! Basic example showing how to create an ArcGIS client with API key authentication.
//!
//! This example demonstrates:
//! - Loading API keys from environment variables (secure pattern)
//! - Creating an API Key authentication provider
//! - Creating an ArcGIS client
//! - Proper error handling with anyhow
//! - Structured logging with tracing
//!
//! # Setup
//!
//! Create a `.env` file in the project root:
//!
//! ```env
//! ARCGIS_API_KEY=your_api_key_here
//! ```
//!
//! The `.env` file is automatically loaded when you create an ArcGIS client.
//! This keeps your credentials out of version control (make sure `.env` is in `.gitignore`).
//!
//! # Running
//!
//! ```bash
//! cargo run --example basic_client
//! ```
use arcgis::example_tracker::ExampleTracker;
use arcgis::{ApiKeyAuth, ApiKeyTier, ArcGISClient};
fn main() -> anyhow::Result<()> {
// Initialize tracing subscriber for structured logging
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
)
.init();
// Start accountability tracking
let tracker = ExampleTracker::new("basic_client")
.service_type("ArcGISClient")
.start();
tracing::info!("Starting basic_client example");
// Load API key from environment (.env file automatically loaded)
tracing::info!("Creating API key authentication provider from environment");
let auth = ApiKeyAuth::from_env(ApiKeyTier::Public)?;
// Create the ArcGIS client
tracing::info!("Creating ArcGIS client");
let client = ArcGISClient::new(auth);
tracing::info!("ArcGIS client created successfully");
tracing::debug!(http_client = ?client.http(), "HTTP client ready");
tracing::info!("Next steps:");
tracing::info!(" - Check out examples/client_credentials_flow.rs for OAuth");
tracing::info!(" - See examples/edit_session.rs for feature editing");
// Mark tracking as successful
tracker.success();
Ok(())
}