koios_sdk/
lib.rs

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// lib.rs documentation update
//! Koios SDK - A Rust SDK for the Koios Cardano API
//!
//! This crate provides a strongly-typed client for interacting with the Koios API,
//! which provides access to Cardano blockchain data. Koios is a decentralized and
//! elastic RESTful query layer for exploring data on the Cardano blockchain.
//!
//! # Features
//!
//! - Strongly typed API client
//! - Support for multiple networks (Mainnet, Preprod, Preview, Guild)
//! - Authentication support (JWT Bearer tokens)
//! - Rate limiting
//! - Async/await support
//! - Comprehensive error handling
//! - Full coverage of Koios API endpoints
//!
//! # Example
//!
//! ```rust,no_run
//! use koios_sdk::{Client, Network, error::Result};
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//!     // Create a client with default configuration (Mainnet)
//!     let client = Client::new()?;
//!
//!     // Or specify a different network
//!     let client = Client::builder()
//!         .network(Network::Preprod)
//!         .build()?;
//!
//!     // Get the current tip of the blockchain
//!     let tip = client.get_tip().await?;
//!     println!("Current tip: {:?}", tip);
//!
//!     Ok(())
//! }
//! ```
//!
//! # Network Selection
//!
//! The SDK supports multiple Cardano networks:
//!
//! ```rust,no_run
//! use koios_sdk::{Client, Network};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     // Connect to Preprod network
//!     let preprod_client = Client::builder()
//!         .network(Network::Preprod)
//!         .build()?;
//!
//!     // Connect to Preview network
//!     let preview_client = Client::builder()
//!         .network(Network::Preview)
//!         .build()?;
//!
//!     // Connect to Guild network
//!     let guild_client = Client::builder()
//!         .network(Network::Guild)
//!         .build()?;
//!
//!     Ok(())
//! }
//! ```
//!
//! # Authentication
//!
//! You can authenticate using a JWT Bearer token:
//!
//! ```rust,no_run
//! use koios_sdk::ClientBuilder;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     let client = ClientBuilder::new()
//!         .auth_token("your-jwt-token")
//!         .build()?;
//!
//!     Ok(())
//! }
//! ```
//!
//! # Rate Limiting
//!
//! The SDK includes built-in rate limiting:
//!
//! ```rust,no_run
//! use koios_sdk::ClientBuilder;
//! use governor::Quota;
//! use std::num::NonZeroU32;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//!     let client = ClientBuilder::new()
//!         .rate_limit(Quota::per_second(NonZeroU32::new(100).unwrap()))
//!         .build()?;
//!
//!     Ok(())
//! }
//! ```
//!
//! # Modules
//!
//! - [`client`] - Client implementation and builder
//! - [`api`] - API endpoint implementations
//! - [`models`] - Data models and types
//! - [`error`] - Error types and handling
//! - [`network`] - Network configuration and options

#![forbid(unsafe_code)]
#![warn(
    missing_debug_implementations,
    missing_copy_implementations,
    trivial_casts,
    trivial_numeric_casts,
    unused_import_braces,
    unused_qualifications,
    rust_2018_idioms
)]
#![allow(dead_code)]

pub mod api;
pub mod client;
pub mod error;
pub mod models;
pub mod network;
pub mod types;
mod utils;

pub use client::{Client, ClientBuilder};
pub use error::{Error, Result};
pub use network::Network;

/// Re-export of commonly used types
pub mod prelude {
    pub use crate::client::{Client, ClientBuilder};
    pub use crate::error::{Error, Result};
    pub use crate::models;
    pub use crate::network::Network;
    pub use crate::types::*;
}

// Version of the crate
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

// API version supported by this SDK
pub const API_VERSION: &str = "v1";

// Default API URL
pub const DEFAULT_API_URL: &str = "https://api.koios.rest/api/v1";