Skip to main content

timeweb_rs/
lib.rs

1//! # timeweb-rs
2//!
3//! Async Rust SDK for the [Timeweb Cloud](https://timeweb.cloud/?i=137383) API.
4//!
5//! The [`apis`] and [`models`] modules are generated from the official Timeweb
6//! Cloud `OpenAPI` specification, so the SDK covers the full public API
7//! surface: cloud servers, managed databases, Kubernetes, projects, domains, S3
8//! storage, load balancers, firewalls, mail, AI agents and everything else
9//! exposed by the control panel.
10//!
11//! ## Authentication
12//!
13//! Timeweb Cloud authenticates requests with a JWT token issued in the control
14//! panel (section "API и Terraform"). Build an authenticated configuration
15//! with [`authenticated`] and pass it to any function in [`apis`]:
16//!
17//! ```no_run
18//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
19//! use timeweb_rs::apis::servers_api;
20//!
21//! let config = timeweb_rs::authenticated("your-jwt-token");
22//! let servers = servers_api::get_servers(&config, None, None).await?;
23//! println!("{servers:#?}");
24//! # Ok(())
25//! # }
26//! ```
27//!
28//! ## Layout
29//!
30//! * [`apis`] — one module per API area ([`apis::servers_api`],
31//!   [`apis::databases_api`], ...); every operation is a free async function
32//!   taking `&Configuration` as its first argument.
33//! * [`models`] — request and response types.
34//! * [`apis::configuration::Configuration`] — connection settings and
35//!   credentials; build it with [`authenticated`].
36//! * [`apis::Error`] — the error type returned by every API call.
37//! * [`TimewebClient`] — the same operations with retries under a configurable
38//!   [`RetryPolicy`].
39//! * [`paginate`] — offset pagination as a stream of items.
40//! * [`ErrorDetails`] — the uniform error envelope carried by every error
41//!   response body.
42
43#![forbid(unsafe_code)]
44
45/// Generated API client modules, one per Timeweb Cloud API area.
46///
47/// Produced by `openapi-generator`; lint groups are relaxed for this generated
48/// code so the hand-written crate code stays under strict lints.
49#[allow(
50    clippy::all,
51    clippy::pedantic,
52    clippy::nursery,
53    unused_imports,
54    rustdoc::all
55)]
56pub mod apis;
57
58/// Generated request and response types.
59///
60/// Produced by `openapi-generator`; see [`apis`] for the lint rationale.
61#[allow(
62    clippy::all,
63    clippy::pedantic,
64    clippy::nursery,
65    unused_imports,
66    rustdoc::all
67)]
68pub mod models;
69
70mod client;
71mod error_body;
72mod pagination;
73mod retry;
74
75pub use client::{DEFAULT_BASE_URL, authenticated, authenticated_with_base_url};
76pub use error_body::{ErrorDetails, ErrorMessage};
77pub use pagination::{PageStream, paginate};
78pub use retry::{RetryPolicy, TimewebClient};