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 Steps

  1. Installation

    composer require spatie/laravel-rdap
    

    Publish the config file (optional, but recommended for customization):

    php artisan vendor:publish --provider="Spatie\Rdap\RdapServiceProvider"
    
  2. First Query Use the Rdap facade to fetch domain data:

    use Spatie\Rdap\Facades\Rdap;
    
    $domainData = Rdap::query('example.com');
    

    This returns a Spatie\Rdap\Domain object containing structured RDAP data (e.g., registrant, nameservers, events).

  3. Where to Look First

    • Facade: Spatie\Rdap\Facades\Rdap (primary entry point).
    • Config: config/rdap.php (caching, HTTP client, and timeout settings).
    • Domain Model: Spatie\Rdap\Domain (understand the structure of returned data).

Implementation Patterns

Core Workflows

  1. Basic Domain Lookup

    $domain = Rdap::query('google.com');
    $registrant = $domain->registrant->name; // Access nested properties
    
    • Useful for domain validation, registrant info, or abuse contact retrieval.
  2. Caching Responses The package caches responses by default (TTL: 24 hours). Override in config:

    'cache_ttl_in_minutes' => 60, // Cache for 1 hour
    
  3. Handling Errors RDAP queries may fail (e.g., unsupported TLDs). Use try-catch:

    try {
        $domain = Rdap::query('nonexistent.tld');
    } catch (\Spatie\Rdap\Exceptions\RdapException $e) {
        // Handle unsupported TLDs or network errors
    }
    
  4. Custom HTTP Client Extend the default Guzzle client by binding a custom one in the service provider:

    $this->app->bind(\Spatie\Rdap\RdapClient::class, function ($app) {
        return new \GuzzleHttp\Client(['timeout' => 10]);
    });
    
  5. Bulk Queries For multiple domains, loop and cache individually:

    $domains = ['example.com', 'google.com'];
    $results = collect($domains)->map(fn ($domain) => Rdap::query($domain));
    

Integration Tips

  • Laravel Models: Attach RDAP data to Eloquent models via accessors:
    public function getRegistrantAttribute() {
        return Rdap::query($this->domain)->registrant->name;
    }
    
  • Jobs: Offload RDAP queries to queues (e.g., for bulk processing):
    Rdap::dispatch('example.com')->onQueue('rdap');
    
  • API Responses: Serialize RDAP data for APIs:
    return response()->json([
        'domain' => Rdap::query($request->domain)->toArray(),
    ]);
    

Gotchas and Tips

Pitfalls

  1. Unsupported TLDs

    • RDAP doesn’t support all TLDs (e.g., .com works, but some newer TLDs may not).
    • Fix: Fall back to WHOIS or handle exceptions gracefully.
  2. Rate Limiting

    • Some RDAP servers throttle requests. Use exponential backoff or caching aggressively.
  3. Data Structure Variability

    • RDAP responses vary by TLD. Always validate properties before accessing:
    if ($domain->registrant) {
        $name = $domain->registrant->name;
    }
    
  4. Caching Quirks

    • Cache keys include the domain name. Clear cache manually if needed:
    Cache::forget("rdap:example.com");
    

Debugging

  • Enable Debugging Set debug to true in config/rdap.php to log raw RDAP responses:
    'debug' => env('RDAP_DEBUG', false),
    
  • Check HTTP Status Codes Use RdapClient::get() directly to inspect raw responses:
    $response = app(\Spatie\Rdap\RdapClient::class)->get('example.com');
    

Extension Points

  1. Custom RDAP Endpoints Override the default endpoint (https://rdap.verisign.com/com/v1/domain) in config:

    'endpoints' => [
        'com' => 'https://custom-rdap.example.com/com/v1/domain',
    ],
    
  2. Extend Domain Model Add custom methods to Spatie\Rdap\Domain via traits or inheritance:

    trait DomainExtensions {
        public function isRecentlyRegistered() {
            return $this->events->contains('eventAction', 'registration') &&
                   $this->events->last()->eventDate->diffInDays() < 30;
        }
    }
    
  3. Mock RDAP for Testing Use Laravel’s HTTP mocking:

    Http::fake([
        'https://rdap.example.com/*' => Http::response(['data' => 'mock'], 200),
    ]);
    
  4. Handle Pagination Some RDAP responses paginate results. Use RdapClient::get() with custom logic:

    $client = app(\Spatie\Rdap\RdapClient::class);
    $response = $client->get('example.com', ['size' => 100]);
    
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport