Aller au contenu principal

Rust SDK

neivi-iqx-lookup — Rust client for the IQX Lookup API using reqwest (blocking).

Installation

Add to your Cargo.toml:

[dependencies]
neivi-iqx-lookup = "0.2.1"

Quick Start

use iqx_lookup::IqxLookup;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = IqxLookup::builder()
.api_key("ALk-your-api-key")
.build()?;

// Validate an email
let email = client.validate_email("user@example.com")?;
println!("Valid format: {}", email.valid_format);
println!("Disposable: {}", email.disposable_email);

// Validate a phone number
let phone = client.validate_phone("+34912345678", Some("ES"))?;
println!("Valid: {}", phone.valid);

// Geolocate an IP
let ip = client.geolocate_ip(Some("8.8.8.8"))?;
println!("Country: {}", ip.country_name);

// Validate a VAT number
let vat = client.validate_vat("ES", "B87387775")?;
println!("Valid: {}", vat.valid);

// Parse a user-agent string
let ua = client.parse_user_agent(Some("Mozilla/5.0..."))?;
println!("Browser: {}", ua.browser_family);

Ok(())
}

Configuration

use std::time::Duration;

let client = IqxLookup::builder()
.api_key("ALk-your-api-key") // required
.base_url("https://api.iqxlookup.neivi.es") // optional
.timeout(Duration::from_secs(15)) // optional, default 10s
.build()?;

API Reference

All methods return Result<T, IqxLookupError>:

MethodReturnsDescription
validate_email(&self, address)EmailValidationResultEmail format, MX, disposable, free provider checks
validate_phone(&self, number, country_code)PhoneValidationResultPhone validation (Option<&str>)
geolocate_ip(&self, ip)IpGeolocationIP geolocation + ASN (None = caller's IP)
validate_vat(&self, country_code, number)VatValidationResultEU VIES VAT validation
parse_user_agent(&self, ua)UserAgentResultUA parsing — browser, OS, device brand & model
validate_iban(&self, iban)IbanValidationResultIBAN structure, checksum, bank info
validate_bic(&self, bic)BicValidationResultBIC/SWIFT format, institution info
lookup_dns(&self, domain, types)DnsLookupResultDNS records, SPF/DKIM/DMARC security
check_ssl(&self, domain)SslCertificateResultSSL certificate, chain, grade
analyze_password(&self, password)PasswordStrengthResultStrength score, crack time, breach check
validate_credit_card(&self, number)CreditCardValidationResultLuhn check, card network, BIN lookup
last_rate_limit_info(&self)Option<RateLimitInfo>Rate limit from last response

Error Handling

use iqx_lookup::IqxLookupError;

match client.validate_email("user@example.com") {
Ok(result) => println!("Valid: {}", result.valid_format),
Err(IqxLookupError::RateLimited { retry_after, .. }) => {
println!("Retry after: {}s", retry_after);
}
Err(IqxLookupError::Unauthorized { .. }) => {
println!("Check your API key");
}
Err(e) => eprintln!("Error: {}", e),
}

Error Variants

VariantHTTP StatusDescription
Unauthorized401Missing API key
Forbidden403Invalid or inactive API key
NotFound404Resource not found
RateLimited429Rate limit exceeded (with retry_after, limit, remaining, reset)
ServiceUnavailable503Service not configured
HttpotherGeneric HTTP error
RequestNetwork/transport error
ConfigBuilder configuration error

Requirements

  • Rust 2021 edition
  • Dependencies: reqwest (blocking), serde, serde_json, thiserror