Overview
The RdapRequest type represents an RDAP query request. It encapsulates the query type, query string, and optional server URL for targeted queries.
Structure
pub struct RdapRequest {
pub query_type: QueryType,
pub query: String,
pub server: Option<Url>,
}
The type of RDAP query to perform (Domain, IP, Autnum, etc.)
The query string (domain name, IP address, AS number, etc.)
Optional specific RDAP server URL. If not set, uses bootstrap discovery.
Constructor
new()
Create a new RDAP request.
pub fn new(query_type: QueryType, query: impl Into<String>) -> Self
The type of query to perform
query
impl Into<String>
required
The query string (automatically converted from &str, String, etc.)
Returns a new request with no specific server set
Example:
use rdap::{RdapRequest, QueryType};
// Domain query
let request = RdapRequest::new(QueryType::Domain, "example.com");
// IP query
let request = RdapRequest::new(QueryType::Ip, "8.8.8.8");
// AS number query
let request = RdapRequest::new(QueryType::Autnum, "AS15169");
// Entity query
let request = RdapRequest::new(QueryType::Entity, "ENTITY-123");
Configuration Methods
with_server()
Set a specific RDAP server URL to query instead of using bootstrap discovery.
pub fn with_server(self, server: Url) -> Self
The base URL of the RDAP server to query
Returns self for method chaining
Example:
use rdap::{RdapRequest, QueryType};
use url::Url;
let request = RdapRequest::new(QueryType::Domain, "example.com")
.with_server(Url::parse("https://rdap.verisign.com/com/v1/")?};
URL Building
build_url()
Build the full RDAP query URL from a base server URL.
pub fn build_url(&self, base_url: &Url) -> Result<Url>
The base URL of the RDAP server
Returns the complete RDAP query URL or an error
URL Patterns:
- Domain/TLD:
{base}/domain/{encoded_query}
- IP:
{base}/ip/{query} (no encoding)
- Autnum:
{base}/autnum/{asn} (strips “AS” prefix)
- Entity:
{base}/entity/{encoded_query}
- Nameserver:
{base}/nameserver/{encoded_query}
- Help:
{base}/help
- Domain Search:
{base}/domains?name={encoded_query}
- Domain Search by NS:
{base}/domains?nsLdhName={encoded_query}
- Domain Search by NS IP:
{base}/domains?nsIp={query}
- Nameserver Search:
{base}/nameservers?name={encoded_query}
- Nameserver Search by IP:
{base}/nameservers?ip={query}
- Entity Search:
{base}/entities?fn={encoded_query}
- Entity Search by Handle:
{base}/entities?handle={encoded_query}
Example:
use rdap::{RdapRequest, QueryType};
use url::Url;
let request = RdapRequest::new(QueryType::Domain, "example.com");
let base = Url::parse("https://rdap.verisign.com/com/v1/")?;
let url = request.build_url(&base)?;
assert_eq!(url.as_str(), "https://rdap.verisign.com/com/v1/domain/example.com");
IPv6 Example:
use rdap::{RdapRequest, QueryType};
use url::Url;
let request = RdapRequest::new(QueryType::Ip, "2001:db8::1");
let base = Url::parse("https://rdap.apnic.net/")?;
let url = request.build_url(&base)?;
assert_eq!(url.as_str(), "https://rdap.apnic.net/ip/2001:db8::1");
AS Number Example:
use rdap::{RdapRequest, QueryType};
use url::Url;
let request = RdapRequest::new(QueryType::Autnum, "AS15169");
let base = Url::parse("https://rdap.arin.net/registry/")?;
let url = request.build_url(&base)?;
// "AS" prefix is automatically stripped
assert_eq!(url.as_str(), "https://rdap.arin.net/registry/autnum/15169");
Query Type Detection
detect_type()
Automatically detect the query type from a query string.
pub fn detect_type(query: &str) -> Result<QueryType>
The query string to analyze
Returns the detected query type or an error
Detection Logic:
- AS Number: Starts with “AS” followed by digits, or pure digits ≤ 4,294,967,294
- IP Address: Matches IPv4, IPv6, or CIDR notation patterns
- TLD: Single word without dots (when using
detect_type_with_tld_check)
- Domain: Default fallback for everything else
Example:
use rdap::{RdapRequest, QueryType};
// Domain
let query_type = RdapRequest::detect_type("example.com")?;
assert_eq!(query_type, QueryType::Domain);
// IPv4
let query_type = RdapRequest::detect_type("192.0.2.1")?;
assert_eq!(query_type, QueryType::Ip);
// IPv6
let query_type = RdapRequest::detect_type("2001:db8::1")?;
assert_eq!(query_type, QueryType::Ip);
// AS Number with prefix
let query_type = RdapRequest::detect_type("AS15169")?;
assert_eq!(query_type, QueryType::Autnum);
// AS Number without prefix
let query_type = RdapRequest::detect_type("15169")?;
assert_eq!(query_type, QueryType::Autnum);
detect_type_with_tld_check()
Detect query type with custom TLD validation.
pub fn detect_type_with_tld_check<F>(query: &str, is_tld: F) -> Result<QueryType>
where
F: Fn(&str) -> bool,
The query string to analyze
is_tld
F: Fn(&str) -> bool
required
Function that returns true if the input is a valid TLD
Returns the detected query type or an error
Example:
use rdap::{RdapRequest, QueryType};
use std::collections::HashSet;
let tlds: HashSet<String> = ["com", "org", "net", "google"]
.iter()
.map(|s| s.to_string())
.collect();
let is_tld = |s: &str| tlds.contains(s);
// Detected as TLD (single word that's in the list)
let query_type = RdapRequest::detect_type_with_tld_check("google", is_tld)?;
assert_eq!(query_type, QueryType::Tld);
// Detected as Domain (has dot)
let query_type = RdapRequest::detect_type_with_tld_check("google.com", is_tld)?;
assert_eq!(query_type, QueryType::Domain);
Usage Patterns
Simple Query
use rdap::{RdapClient, RdapRequest, QueryType};
let client = RdapClient::new()?;
let request = RdapRequest::new(QueryType::Domain, "example.com");
let result = client.query(&request).await?;
Query with Specific Server
use rdap::{RdapClient, RdapRequest, QueryType};
use url::Url;
let client = RdapClient::new()?;
let request = RdapRequest::new(QueryType::Domain, "example.com")
.with_server(Url::parse("https://rdap.verisign.com/com/v1/")?);
let result = client.query(&request).await?;
Auto-Detect Query Type
use rdap::{RdapClient, RdapRequest};
let client = RdapClient::new()?;
let query_type = RdapRequest::detect_type("example.com")?;
let request = RdapRequest::new(query_type, "example.com");
let result = client.query(&request).await?;
Search Query
use rdap::{RdapClient, RdapRequest, QueryType};
let client = RdapClient::new()?;
let request = RdapRequest::new(QueryType::DomainSearch, "example*")
.with_server(Url::parse("https://rdap.verisign.com/com/v1/")?);
let result = client.query(&request).await?;
match result {
RdapObject::DomainSearch(search) => {
for domain in search.domains {
println!("Found: {:?}", domain.ldh_name);
}
}
_ => println!("Unexpected result type"),
}