Skip to main content

namecheap_client/
lib.rs

1//! An unofficial, async Rust client for the [Namecheap](https://www.namecheap.com)
2//! API.
3//!
4//! This crate wraps the parts of the Namecheap API needed to check, register,
5//! and configure domains, so you do not have to hand-roll HTTP requests and XML
6//! parsing. It is **not** affiliated with or endorsed by Namecheap.
7//!
8//! # Supported commands
9//!
10//! - [`Client::domains().check()`](domains::Domains::check) -
11//!   `namecheap.domains.check`
12//! - [`Client::domains().create()`](domains::Domains::create) -
13//!   `namecheap.domains.create`
14//! - [`Client::domains().list()`](domains::Domains::list) -
15//!   `namecheap.domains.getList`
16//! - [`Client::domains().set_auto_renew()`](domains::Domains::set_auto_renew) -
17//!   `namecheap.domains.setAutoRenew`
18//! - [`Client::domains().dns().get_hosts()`](domains::Dns::get_hosts) -
19//!   `namecheap.domains.dns.getHosts`
20//! - [`Client::domains().dns().set_hosts()`](domains::Dns::set_hosts) -
21//!   `namecheap.domains.dns.setHosts`
22//! - [`Client::users().get_balances()`](users::Users::get_balances) -
23//!   `namecheap.users.getBalances`
24//!
25//! # Requirements
26//!
27//! Every request is authenticated with your API user, API key, and account
28//! username, and must originate from an IP address you have whitelisted in the
29//! Namecheap API settings. That same address is sent as the `ClientIp`
30//! parameter, so it must match your real outbound public IPv4 address.
31//!
32//! # Example
33//!
34//! ```no_run
35//! use namecheap_client::{Client, Environment};
36//!
37//! #[tokio::main]
38//! async fn main() -> Result<(), namecheap_client::Error> {
39//!     let client = Client::builder()
40//!         .api_user("your-api-user")
41//!         .api_key("your-api-key")
42//!         .client_ip("203.0.113.10") // your whitelisted public IPv4
43//!         .environment(Environment::Sandbox)
44//!         .build()?;
45//!
46//!     for result in client.domains().check(["example.com", "rust-lang.org"]).await? {
47//!         println!("{}: available = {}", result.domain, result.available);
48//!     }
49//!
50//!     Ok(())
51//! }
52//! ```
53//!
54//! # TLS backends
55//!
56//! By default the crate uses [`rustls`](https://github.com/rustls/rustls) so it
57//! builds without a system OpenSSL installation. To use the platform-native TLS
58//! stack instead, disable default features and enable `native-tls`:
59//!
60//! ```toml
61//! namecheap-client = { version = "0.1", default-features = false, features = ["native-tls"] }
62//! ```
63
64#![forbid(unsafe_code)]
65#![warn(missing_docs)]
66#![warn(rust_2018_idioms)]
67
68mod client;
69mod error;
70mod response;
71
72pub mod domains;
73pub mod users;
74
75pub use client::{Client, ClientBuilder, Environment};
76pub use error::{ApiError, ApiErrorEntry, Error, Result};
77
78pub use domains::{
79    Contact, Dns, DomainCheckResult, DomainCreateRequest, DomainCreateResult, DomainListItem,
80    DomainListResult, Domains, EmailType, GetHostsResult, HostInfo, HostRecord, RecordType,
81    SetAutoRenewResult, SetHostsRequest, SetHostsResult,
82};
83pub use users::{Balances, Users};