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//! - [`Client::users().get_pricing()`](users::Users::get_pricing) -
25//!   `namecheap.users.getPricing`
26//!
27//! # Requirements
28//!
29//! Every request is authenticated with your API user, API key, and account
30//! username, and must originate from an IP address you have whitelisted in the
31//! Namecheap API settings. That same address is sent as the `ClientIp`
32//! parameter, so it must match your real outbound public IPv4 address.
33//!
34//! # Example
35//!
36//! ```no_run
37//! use namecheap_client::{Client, Environment};
38//!
39//! #[tokio::main]
40//! async fn main() -> Result<(), namecheap_client::Error> {
41//!     let client = Client::builder()
42//!         .api_user("your-api-user")
43//!         .api_key("your-api-key")
44//!         .client_ip("203.0.113.10") // your whitelisted public IPv4
45//!         .environment(Environment::Sandbox)
46//!         .build()?;
47//!
48//!     for result in client.domains().check(["example.com", "rust-lang.org"]).await? {
49//!         println!("{}: available = {}", result.domain, result.available);
50//!     }
51//!
52//!     Ok(())
53//! }
54//! ```
55//!
56//! # TLS backends
57//!
58//! By default the crate uses [`rustls`](https://github.com/rustls/rustls) so it
59//! builds without a system OpenSSL installation. To use the platform-native TLS
60//! stack instead, disable default features and enable `native-tls`:
61//!
62//! ```toml
63//! namecheap-client = { version = "0.1", default-features = false, features = ["native-tls"] }
64//! ```
65
66#![forbid(unsafe_code)]
67#![warn(missing_docs)]
68#![warn(rust_2018_idioms)]
69
70mod client;
71mod error;
72mod response;
73
74pub mod domains;
75pub mod users;
76
77pub use client::{Client, ClientBuilder, Environment};
78pub use error::{ApiError, ApiErrorEntry, Error, Result};
79
80pub use domains::{
81    Contact, Dns, DomainCheckResult, DomainCreateRequest, DomainCreateResult, DomainListItem,
82    DomainListResult, Domains, EmailType, GetHostsResult, HostInfo, HostRecord, RecordType,
83    SetAutoRenewResult, SetHostsRequest, SetHostsResult,
84};
85pub use users::{
86    Balances, Price, PricingRequest, PricingResult, ProductCategoryPricing, ProductPricing,
87    ProductTypePricing, Users,
88};