koios_sdk/
lib.rs

1// lib.rs documentation update
2//! Koios SDK - A Rust SDK for the Koios Cardano API
3//!
4//! This crate provides a strongly-typed client for interacting with the Koios API,
5//! which provides access to Cardano blockchain data. Koios is a decentralized and
6//! elastic RESTful query layer for exploring data on the Cardano blockchain.
7//!
8//! # Features
9//!
10//! - Strongly typed API client
11//! - Support for multiple networks (Mainnet, Preprod, Preview, Guild)
12//! - Authentication support (JWT Bearer tokens)
13//! - Rate limiting
14//! - Async/await support
15//! - Comprehensive error handling
16//! - Full coverage of Koios API endpoints
17//!
18//! # Example
19//!
20//! ```rust,no_run
21//! use koios_sdk::{Client, Network, error::Result};
22//!
23//! #[tokio::main]
24//! async fn main() -> Result<()> {
25//!     // Create a client with default configuration (Mainnet)
26//!     let client = Client::new()?;
27//!
28//!     // Or specify a different network
29//!     let client = Client::builder()
30//!         .network(Network::Preprod)
31//!         .build()?;
32//!
33//!     // Get the current tip of the blockchain
34//!     let tip = client.get_tip().await?;
35//!     println!("Current tip: {:?}", tip);
36//!
37//!     Ok(())
38//! }
39//! ```
40//!
41//! # Network Selection
42//!
43//! The SDK supports multiple Cardano networks:
44//!
45//! ```rust,no_run
46//! use koios_sdk::{Client, Network};
47//!
48//! #[tokio::main]
49//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
50//!     // Connect to Preprod network
51//!     let preprod_client = Client::builder()
52//!         .network(Network::Preprod)
53//!         .build()?;
54//!
55//!     // Connect to Preview network
56//!     let preview_client = Client::builder()
57//!         .network(Network::Preview)
58//!         .build()?;
59//!
60//!     // Connect to Guild network
61//!     let guild_client = Client::builder()
62//!         .network(Network::Guild)
63//!         .build()?;
64//!
65//!     Ok(())
66//! }
67//! ```
68//!
69//! # Authentication
70//!
71//! You can authenticate using a JWT Bearer token:
72//!
73//! ```rust,no_run
74//! use koios_sdk::ClientBuilder;
75//!
76//! #[tokio::main]
77//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
78//!     let client = ClientBuilder::new()
79//!         .auth_token("your-jwt-token")
80//!         .build()?;
81//!
82//!     Ok(())
83//! }
84//! ```
85//!
86//! # Rate Limiting
87//!
88//! The SDK includes built-in rate limiting:
89//!
90//! ```rust,no_run
91//! use koios_sdk::ClientBuilder;
92//! use governor::Quota;
93//! use std::num::NonZeroU32;
94//!
95//! #[tokio::main]
96//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
97//!     let client = ClientBuilder::new()
98//!         .rate_limit(Quota::per_second(NonZeroU32::new(100).unwrap()))
99//!         .build()?;
100//!
101//!     Ok(())
102//! }
103//! ```
104//!
105//! # Modules
106//!
107//! - [`client`] - Client implementation and builder
108//! - [`api`] - API endpoint implementations
109//! - [`models`] - Data models and types
110//! - [`error`] - Error types and handling
111//! - [`network`] - Network configuration and options
112
113#![forbid(unsafe_code)]
114#![warn(
115    missing_debug_implementations,
116    missing_copy_implementations,
117    trivial_casts,
118    trivial_numeric_casts,
119    unused_import_braces,
120    unused_qualifications,
121    rust_2018_idioms
122)]
123#![allow(dead_code)]
124
125pub mod api;
126pub mod client;
127pub mod error;
128pub mod models;
129pub mod network;
130pub mod types;
131mod utils;
132
133pub use client::{Client, ClientBuilder};
134pub use error::{Error, Result};
135pub use network::Network;
136
137/// Re-export of commonly used types
138pub mod prelude {
139    pub use crate::client::{Client, ClientBuilder};
140    pub use crate::error::{Error, Result};
141    pub use crate::models;
142    pub use crate::network::Network;
143    pub use crate::types::*;
144}
145
146// Version of the crate
147pub const VERSION: &str = env!("CARGO_PKG_VERSION");
148
149// API version supported by this SDK
150pub const API_VERSION: &str = "v1";
151
152// Default API URL
153pub const DEFAULT_API_URL: &str = "https://api.koios.rest/api/v1";