Skip to main content

gcp_lite_rs/
lib.rs

1//! Lightweight HTTP-based client for Google Cloud Platform APIs.
2//!
3//! `gcp-http-lite` provides clean REST API access without the overhead of gRPC.
4//! It includes automatic retry, backoff, structured errors, and multi-tenant support.
5//!
6//! # Quick Start
7//!
8//! ```no_run
9//! use gcp_lite::{GcpHttpClient, token::StaticTokenProvider};
10//!
11//! # #[tokio::main]
12//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
13//! let provider = StaticTokenProvider::new("your-token");
14//! let client = GcpHttpClient::builder()
15//!     .token_provider(provider)
16//!     .build()?;
17//!
18//! let compute = client.compute();
19//! # Ok(())
20//! # }
21//! ```
22
23#![warn(missing_docs)]
24#![warn(clippy::all)]
25
26pub mod api;
27pub mod auth;
28pub mod client;
29pub mod error;
30pub mod operation;
31pub(crate) mod ops;
32pub mod rate_limit;
33pub mod retry;
34pub(crate) mod serde_base64;
35pub mod token;
36pub mod types;
37
38#[cfg(feature = "test-support")]
39pub mod mock_client;
40
41#[cfg(any(test, feature = "test-support"))]
42pub mod test_support;
43
44#[cfg(test)]
45mod fixture_tests;
46
47#[cfg(test)]
48mod test_support_demo;
49
50pub use client::{BuilderError, GcpHttpClient, GcpHttpClientBuilder};
51pub use error::{GcpError, Result};
52pub use operation::{
53    ContainerOperation, GkeBackupOperation, Operation, PollConfig, ServiceUsageOperation,
54    SqlOperation,
55};
56pub use rate_limit::{RateLimitConfig, RateLimitStats};
57pub use retry::RetryConfig;
58
59/// Build a URL query string from key-value pairs, omitting any with empty values.
60pub(crate) fn append_query_params(url: String, params: &[(&str, &str)]) -> String {
61    let qs: Vec<String> = params
62        .iter()
63        .filter(|(_, v)| !v.is_empty())
64        .map(|(k, v)| format!("{}={}", k, urlencoding::encode(v)))
65        .collect();
66    if qs.is_empty() {
67        url
68    } else {
69        format!("{}?{}", url, qs.join("&"))
70    }
71}
72
73#[cfg(feature = "test-support")]
74pub use mock_client::MockClient;