domain-check-lib 0.6.0

A fast, robust library for checking domain availability using RDAP and WHOIS protocols
Documentation
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# domain-check-lib

**A fast, robust Rust library for checking domain availability using RDAP and WHOIS protocols**

[![Crates.io](https://img.shields.io/crates/v/domain-check-lib.svg)](https://crates.io/crates/domain-check-lib)
[![Documentation](https://docs.rs/domain-check-lib/badge.svg)](https://docs.rs/domain-check-lib)
[![Downloads](https://img.shields.io/crates/d/domain-check-lib.svg)](https://crates.io/crates/domain-check-lib)
[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

---

## 🚀 Quick Start

Add to your `Cargo.toml`:

```toml
[dependencies]
domain-check-lib = "0.5.0"
tokio = { version = "1", features = ["full"] }
```

**Basic Example:**

```rust
use domain_check_lib::DomainChecker;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let checker = DomainChecker::new();
    let result = checker.check_domain("example.com").await?;
    
    match result.available {
        Some(true) => println!("{} is AVAILABLE", result.domain),
        Some(false) => println!("{} is TAKEN", result.domain),
        None => println!("{} status is UNKNOWN", result.domain),
    }
    
    Ok(())
}
```

---

## ✨ Key Features

🦀 **Pure Async Rust** - Built with tokio for high performance  
🌐 **Dual Protocol Support** - RDAP-first with WHOIS fallback  
⚡ **Concurrent Processing** - Check multiple domains simultaneously  
🎯 **30+ TLD Mappings** - Accurate results across major registries  
🛡️ **Robust Error Handling** - Comprehensive error types with recovery  
📊 **Detailed Information** - Extract registrar, dates, and status codes  
🔄 **Streaming Support** - Real-time results for bulk operations  

---

## 📚 Usage Examples

### Single Domain Check

```rust
use domain_check_lib::{DomainChecker, CheckConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let checker = DomainChecker::new();
    
    let result = checker.check_domain("google.com").await?;
    
    println!("Domain: {}", result.domain);
    println!("Available: {:?}", result.available);
    println!("Method used: {}", result.method_used);
    
    Ok(())
}
```

### Bulk Domain Checking

```rust
use domain_check_lib::{DomainChecker, CheckConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = CheckConfig::default()
        .with_concurrency(20)
        .with_detailed_info(true);
    
    let checker = DomainChecker::with_config(config);
    let domains = vec![
        "example.com".to_string(),
        "google.org".to_string(),
        "github.io".to_string(),
    ];
    
    let results = checker.check_domains(&domains).await?;
    
    for result in results {
        match result.available {
            Some(true) => println!("✅ {} is available", result.domain),
            Some(false) => println!("❌ {} is taken", result.domain),
            None => println!("❓ {} status unknown", result.domain),
        }
    }
    
    Ok(())
}
```

### Streaming Results (Real-time)

```rust
use domain_check_lib::DomainChecker;
use futures::StreamExt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let checker = DomainChecker::new();
    let domains = vec![
        "example.com".to_string(),
        "startup.org".to_string(),
        "mybrand.net".to_string(),
    ];
    
    let mut stream = checker.check_domains_stream(&domains);
    
    while let Some(result) = stream.next().await {
        match result {
            Ok(domain_result) => {
                println!("✓ {}: {:?}", domain_result.domain, domain_result.available);
            }
            Err(e) => {
                eprintln!("✗ Error: {}", e);
            }
        }
    }
    
    Ok(())
}
```

### Custom Configuration

```rust
use domain_check_lib::{DomainChecker, CheckConfig};
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = CheckConfig::default()
        .with_concurrency(50)                          // Max 50 concurrent checks
        .with_timeout(Duration::from_secs(10))         // 10 second timeout
        .with_whois_fallback(true)                     // Enable WHOIS fallback
        .with_bootstrap(true)                          // Use IANA bootstrap
        .with_detailed_info(true);                     // Extract full domain info
    
    let checker = DomainChecker::with_config(config);
    let result = checker.check_domain("example.com").await?;
    
    if let Some(duration) = result.check_duration {
        println!("Checked in {}ms via {}", 
            duration.as_millis(), 
            result.method_used
        );
    }
    
    Ok(())
}
```

### **🆕 TLD Management (v0.5.0)**

The library now provides direct access to TLD knowledge for building domain exploration tools:

```rust
use domain_check_lib::{get_all_known_tlds, get_preset_tlds, get_available_presets};

#[tokio::main] 
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Get all TLDs with RDAP endpoints
    let all_tlds = get_all_known_tlds();
    println!("Checking across {} TLDs", all_tlds.len()); // ~42 TLDs
    
    // Use curated presets for common scenarios
    let startup_tlds = get_preset_tlds("startup").unwrap();
    println!("Startup TLDs: {:?}", startup_tlds); // 8 tech-focused TLDs
    
    // List available presets
    let presets = get_available_presets();
    println!("Available presets: {:?}", presets); // ["startup", "enterprise", "country"]
    
    Ok(())
}
```

### **Smart Domain Expansion**

Combine TLD management with domain expansion for powerful bulk operations:

```rust
use domain_check_lib::{DomainChecker, get_preset_tlds, expand_domain_inputs};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let checker = DomainChecker::new();
    
    // Define base domain names
    let base_names = vec!["myapp".to_string(), "mystartup".to_string()];
    
    // Expand with startup-focused TLDs
    let startup_tlds = get_preset_tlds("startup");
    let domains = expand_domain_inputs(&base_names, &startup_tlds);
    // Results in: myapp.com, myapp.io, myapp.ai, etc.
    
    // Check all expanded domains
    let results = checker.check_domains(&domains).await?;
    
    // Filter for available domains
    let available: Vec<_> = results
        .iter()
        .filter(|r| r.available == Some(true))
        .collect();
        
    println!("Found {} available domains", available.len());
    
    Ok(())
}
```

🌐 **TLD Management**: Access to 40+ known TLDs and curated presets  
🎯 **Smart Expansion**: Intelligent domain name expansion with preset integration  
📊 **Enhanced Results**: Improved error context and domain information

### **Universal TLD Checking**

```rust
use domain_check_lib::{DomainChecker, get_all_known_tlds};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let checker = DomainChecker::new();
    
    // Check against all known TLDs
    let all_tlds = get_all_known_tlds();
    let domains = domain_check_lib::expand_domain_inputs(
        &["myapp".to_string()], 
        &Some(all_tlds)
    );
    
    println!("Checking {} domains across all TLDs", domains.len());
    
    let results = checker.check_domains(&domains).await?;
    
    // Analyze results
    let available_count = results.iter().filter(|r| r.available == Some(true)).count();
    let taken_count = results.iter().filter(|r| r.available == Some(false)).count();
    
    println!("Results: {} available, {} taken", available_count, taken_count);
    
    Ok(())
}
```

### File-based Processing

```rust
use domain_check_lib::DomainChecker;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let checker = DomainChecker::new();
    
    // Process domains from a file (one domain per line)
    let results = checker.check_domains_from_file("domains.txt").await?;
    
    let available_domains: Vec<_> = results
        .iter()
        .filter(|r| r.available == Some(true))
        .collect();
    
    println!("Found {} available domains out of {}", 
        available_domains.len(), 
        results.len()
    );
    
    for domain in available_domains {
        println!("✅ {}", domain.domain);
    }
    
    Ok(())
}
```

---

## 🔧 Configuration Options

The `CheckConfig` struct provides extensive configuration:

```rust
use domain_check_lib::CheckConfig;
use std::time::Duration;

let config = CheckConfig::default()
    .with_concurrency(25)                    // Concurrent requests (1-100)
    .with_timeout(Duration::from_secs(8))    // Per-domain timeout
    .with_whois_fallback(true)               // Enable WHOIS fallback
    .with_bootstrap(false)                   // IANA bootstrap lookup
    .with_detailed_info(true)                // Extract registrar details
    .with_tlds(vec![                         // Default TLDs for expansion
        "com".to_string(),
        "org".to_string(),
        "net".to_string()
    ]);
```

---

## 📊 Data Structures

### DomainResult

```rust
pub struct DomainResult {
    pub domain: String,              // Domain that was checked
    pub available: Option<bool>,     // true = available, false = taken, None = unknown
    pub info: Option<DomainInfo>,    // Detailed registration info (if available)
    pub check_duration: Option<Duration>, // How long the check took
    pub method_used: CheckMethod,    // RDAP, WHOIS, or Bootstrap
    pub error_message: Option<String>, // Error details (if applicable)
}
```

### DomainInfo

```rust
pub struct DomainInfo {
    pub registrar: Option<String>,      // Domain registrar
    pub creation_date: Option<String>,  // When domain was registered
    pub expiration_date: Option<String>, // When domain expires
    pub status: Vec<String>,            // Domain status codes
    pub updated_date: Option<String>,   // Last update date
    pub nameservers: Vec<String>,       // Associated nameservers
}
```

---

## 🌐 Protocol Support

### RDAP (Primary)

- **Modern Protocol**: Structured JSON responses
- **30+ TLD Mappings**: Major registries supported
- **Rich Data**: Registrar info, dates, status codes
- **Performance**: Fast, reliable responses

### WHOIS (Fallback)

- **Universal Coverage**: Works with most TLDs
- **Automatic Parsing**: Intelligent response interpretation
- **Rate Limiting**: Built-in throttling protection
- **Error Recovery**: Smart fallback logic

### Bootstrap Discovery

- **IANA Registry**: Dynamic endpoint discovery
- **Unknown TLDs**: Automatic protocol detection
- **Future Proof**: Adapts to new registries

---

## 🚀 Performance

Domain Check is optimized for high-performance operations:

- **Concurrent Processing**: Configurable parallelism (1-100 concurrent requests)
- **Connection Reuse**: HTTP client connection pooling
- **Smart Timeouts**: Registry-specific timeout optimization
- **Memory Efficient**: Streaming results for large datasets
- **Protocol Selection**: Intelligent RDAP/WHOIS routing

---

## 🛡️ Error Handling

Comprehensive error types with automatic recovery:

```rust
use domain_check_lib::DomainCheckError;

match checker.check_domain("invalid-domain").await {
    Ok(result) => println!("Success: {:?}", result),
    Err(DomainCheckError::InvalidDomain { domain, reason }) => {
        eprintln!("Invalid domain '{}': {}", domain, reason);
    }
    Err(DomainCheckError::NetworkError { message, .. }) => {
        eprintln!("Network error: {}", message);
    }
    Err(DomainCheckError::Timeout { operation, duration }) => {
        eprintln!("Timeout after {:?}: {}", duration, operation);
    }
    Err(e) => eprintln!("Other error: {}", e),
}
```

---

## 🔗 Related Projects

- **CLI Tool**: [`domain-check`]https://crates.io/crates/domain-check - Command-line interface
- **Repository**: [GitHub]https://github.com/saidutt46/domain-check - Source code and issues

---

## 📝 License

This project is licensed under the Apache License, Version 2.0 - see the [LICENSE](../LICENSE) file for details.

---

## 🤝 Contributing

Contributions are welcome! Please see the [Contributing Guide](../CONTRIBUTING.md) for details.

---

*Built with ❤️ in Rust*