Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Rdap Laravel Package

spatie/laravel-rdap

Laravel package for performing RDAP lookups (WHOIS successor) to fetch domain registration data as structured JSON. Includes built-in caching for TLD server discovery and RDAP responses, plus configurable retries/timeouts for unreliable endpoints.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require spatie/laravel-rdap
    php artisan vendor:publish --tag="rdap-config"
    

    This publishes the config file (config/rdap.php) with default caching and retry settings.

  2. First Query: Use the facade to fetch domain or IP data:

    use Spatie\Rdap\Facades\Rdap;
    
    // Domain query
    $domain = Rdap::domain('google.com');
    
    // IP query
    $ip = Rdap::ip('127.0.0.1');
    
  3. Check TLD Support: Verify if a domain's TLD is supported by RDAP:

    if (Rdap::domainIsSupported('example.com')) {
        // Proceed with query
    }
    

Implementation Patterns

Domain Queries

  1. Basic Usage:

    $domain = Rdap::domain('example.com');
    $expiryDate = $domain->expirationDate(); // Carbon instance
    $status = $domain->hasStatus(DomainStatus::ClientTransferProhibited);
    
  2. Custom Servers: Override the default RDAP server for specific queries:

    $domain = Rdap::domain('example.com', dnsServer: 'https://custom-rdap.example.com');
    
  3. Retry Configuration: Adjust retry logic for unreliable RDAP endpoints:

    $domain = Rdap::domain('example.com', [
        'timeoutInSeconds' => 10,
        'retryTimes' => 5,
        'sleepInMillisecondsBetweenRetries' => 2000,
    ]);
    
  4. Data Extraction: Access nested properties using dot notation:

    $registrar = $domain->get('events.0.eventAction'); // e.g., 'registration'
    $allData = $domain->all(); // Full response as array
    

IP Queries

  1. Basic Usage:

    $ip = Rdap::ip('8.8.8.8');
    $network = $ip->get('objectClassName'); // 'ip network'
    
  2. Date Handling:

    $ip->registrationDate(); // Carbon instance
    $ip->lastUpdateOfRdapDb();
    

DNS Server Management

  1. Fetch Server for TLD:

    $serverUrl = Rdap::dns()->getServerForTld('com');
    
  2. List Supported TLDs:

    $supportedTlds = Rdap::dns()->supportedTlds();
    
  3. IP Registry Lookup:

    $ipServer = (new \Spatie\Rdap\RdapIpV4())->getServerForIp('8.8.8.8');
    

Integration Tips

  1. Caching: Leverage built-in caching for TLD servers (default: 1 week) and domain/IP responses (if extended via allnetru's PR).

    // Override cache store (e.g., Redis)
    'tld_servers_cache' => [
        'store_name' => 'redis',
        'duration_in_seconds' => CarbonInterval::day()->totalSeconds,
    ],
    
  2. Error Handling: Catch RdapException for timeouts or invalid responses:

    try {
        $domain = Rdap::domain('unreachable.example');
    } catch (\Spatie\Rdap\Exceptions\RdapException $e) {
        // Log or retry logic
    }
    
  3. Testing: Mock the facade or use stubs for unit tests:

    Rdap::shouldReceive('domain')->andReturn(new DomainResponse());
    

Gotchas and Tips

Pitfalls

  1. Unsupported TLDs: RDAP does not support all TLDs (e.g., .be). Always check domainIsSupported() first.

    if (!Rdap::domainIsSupported('example.be')) {
        throw new \RuntimeException('RDAP not available for .be');
    }
    
  2. Rate Limiting: RDAP servers may throttle requests. Implement exponential backoff for retries:

    $sleepTime = 1000 * (2 ** $retryAttempt);
    
  3. Invalid Responses: Some RDAP servers return malformed JSON. Use the InvalidRdapResponse exception to handle this gracefully.

  4. IPv6 Support: The package primarily supports IPv4. For IPv6, use RdapIpV6 (if extended) or validate input:

    if (filter_var('2001:db8::1', FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
        // Handle IPv6
    }
    

Debugging Tips

  1. Log Raw Responses: Inspect raw RDAP responses for debugging:

    $domain = Rdap::domain('example.com');
    \Log::debug('Raw RDAP response:', $domain->all());
    
  2. Custom DNS Server: Test with a local RDAP server (e.g., Mock RDAP) to debug issues:

    Rdap::domain('test.local', dnsServer: 'http://localhost:3000');
    
  3. Cache Invalidation: Clear caches when TLD server lists update (e.g., via IANA):

    php artisan cache:clear
    

Extension Points

  1. Add Domain/IP Caching: Extend the package to cache responses (see PR #47):

    // Example: Cache domain responses for 1 hour
    $domain = Rdap::domain('example.com');
    Cache::put("rdap_domain_{$domain->get('domainName')}", $domain, now()->addHour());
    
  2. Custom Status Enums: Extend DomainStatus enum for project-specific checks:

    use Spatie\Rdap\Enums\DomainStatus;
    
    class CustomDomainStatus extends DomainStatus {
        public const PendingDeletion = 'pending deletion';
    }
    
  3. Batch Queries: Implement batch processing for multiple domains/IPs:

    $domains = collect(['example.com', 'test.org'])
        ->map(fn ($domain) => Rdap::domain($domain))
        ->filter();
    
  4. Webhook Integration: Trigger actions on domain/IP changes (e.g., expiry alerts):

    $domain = Rdap::domain('example.com');
    if ($domain->expirationDate()->lt(now()->addDays(7))) {
        // Send expiry alert
    }
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony