|
| 1 | +# rdapapi-php |
| 2 | + |
| 3 | +Official PHP SDK for the [RDAP API](https://rdapapi.io) — look up domains, IP addresses, ASNs, nameservers, and entities via the RDAP protocol. |
| 4 | + |
| 5 | +[](https://packagist.org/packages/rdapapi/rdapapi-php) |
| 6 | +[](https://packagist.org/packages/rdapapi/rdapapi-php) |
| 7 | +[](https://github.com/rdapapi/rdapapi-php/actions/workflows/ci.yml) |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +```bash |
| 12 | +composer require rdapapi/rdapapi-php |
| 13 | +``` |
| 14 | + |
| 15 | +Requires PHP 8.2 or later. |
| 16 | + |
| 17 | +## Quick Start |
| 18 | + |
| 19 | +```php |
| 20 | +<?php |
| 21 | + |
| 22 | +use RdapApi\RdapApi; |
| 23 | + |
| 24 | +$api = new RdapApi('your-api-key'); |
| 25 | + |
| 26 | +$domain = $api->domain('google.com'); |
| 27 | + |
| 28 | +echo $domain->registrar->name; // "MarkMonitor Inc." |
| 29 | +echo $domain->dates->registered; // "1997-09-15T04:00:00Z" |
| 30 | +echo $domain->dates->expires; // "2028-09-14T04:00:00Z" |
| 31 | +print_r($domain->nameservers); // ["ns1.google.com", ...] |
| 32 | +``` |
| 33 | + |
| 34 | +## Usage |
| 35 | + |
| 36 | +### Configuration |
| 37 | + |
| 38 | +```php |
| 39 | +use RdapApi\RdapApi; |
| 40 | + |
| 41 | +// Default configuration |
| 42 | +$api = new RdapApi('your-api-key'); |
| 43 | + |
| 44 | +// Custom timeout (in seconds) |
| 45 | +$api = new RdapApi('your-api-key', ['timeout' => 10]); |
| 46 | + |
| 47 | +// Custom base URL |
| 48 | +$api = new RdapApi('your-api-key', ['base_url' => 'https://custom.api.com/v1']); |
| 49 | +``` |
| 50 | + |
| 51 | +### Domain Lookup |
| 52 | + |
| 53 | +```php |
| 54 | +$domain = $api->domain('example.com'); |
| 55 | +echo $domain->domain; // "example.com" |
| 56 | +echo $domain->registrar->name; // Registrar name |
| 57 | +echo $domain->registrar->iana_id; // IANA registrar ID |
| 58 | +echo $domain->dnssec; // true/false |
| 59 | + |
| 60 | +// With registrar follow-through (for thin registries) |
| 61 | +$domain = $api->domain('example.com', ['follow' => true]); |
| 62 | +echo $domain->meta->followed; // true |
| 63 | +``` |
| 64 | + |
| 65 | +### IP Address Lookup |
| 66 | + |
| 67 | +```php |
| 68 | +$ip = $api->ip('8.8.8.8'); |
| 69 | +echo $ip->name; // "LVLT-GOGL-8-8-8" |
| 70 | +echo $ip->country; // "US" |
| 71 | +print_r($ip->cidr); // ["8.8.8.0/24"] |
| 72 | +echo $ip->start_address; // "8.8.8.0" |
| 73 | +echo $ip->end_address; // "8.8.8.255" |
| 74 | +``` |
| 75 | + |
| 76 | +### ASN Lookup |
| 77 | + |
| 78 | +```php |
| 79 | +$asn = $api->asn(15169); // integer |
| 80 | +$asn = $api->asn('AS15169'); // string with prefix (stripped automatically) |
| 81 | + |
| 82 | +echo $asn->name; // "GOOGLE" |
| 83 | +echo $asn->start_autnum; // 15169 |
| 84 | +``` |
| 85 | + |
| 86 | +### Nameserver Lookup |
| 87 | + |
| 88 | +```php |
| 89 | +$ns = $api->nameserver('ns1.google.com'); |
| 90 | +echo $ns->ldh_name; // "ns1.google.com" |
| 91 | +print_r($ns->ip_addresses->v4); // ["216.239.32.10"] |
| 92 | +print_r($ns->ip_addresses->v6); // ["2001:4860:4802:32::a"] |
| 93 | +``` |
| 94 | + |
| 95 | +### Entity Lookup |
| 96 | + |
| 97 | +```php |
| 98 | +$entity = $api->entity('GOGL'); |
| 99 | +echo $entity->name; // "Google LLC" |
| 100 | +echo $entity->organization; // "Google LLC" |
| 101 | +echo $entity->autnums[0]->handle; // "AS15169" |
| 102 | +echo $entity->networks[0]->cidr[0]; // "8.8.8.0/24" |
| 103 | +``` |
| 104 | + |
| 105 | +### Bulk Domain Lookup |
| 106 | + |
| 107 | +Requires a Pro or Business plan. Up to 10 domains per call. |
| 108 | + |
| 109 | +```php |
| 110 | +$resp = $api->bulkDomains( |
| 111 | + ['google.com', 'github.com', 'example.com'], |
| 112 | + ['follow' => true], |
| 113 | +); |
| 114 | + |
| 115 | +echo $resp->summary->total; // 3 |
| 116 | +echo $resp->summary->successful; // 3 |
| 117 | + |
| 118 | +foreach ($resp->results as $result) { |
| 119 | + if ($result->status === 'success') { |
| 120 | + echo "{$result->domain} — {$result->data->registrar->name}\n"; |
| 121 | + } else { |
| 122 | + echo "{$result->domain} — error: {$result->message}\n"; |
| 123 | + } |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +## Error Handling |
| 128 | + |
| 129 | +All API errors are thrown as typed exceptions that extend `RdapApiException`: |
| 130 | + |
| 131 | +```php |
| 132 | +use RdapApi\Exceptions\AuthenticationException; |
| 133 | +use RdapApi\Exceptions\NotFoundException; |
| 134 | +use RdapApi\Exceptions\RateLimitException; |
| 135 | +use RdapApi\Exceptions\SubscriptionRequiredException; |
| 136 | + |
| 137 | +try { |
| 138 | + $domain = $api->domain('example.com'); |
| 139 | +} catch (NotFoundException $e) { |
| 140 | + echo "Not found: {$e->getMessage()}"; |
| 141 | +} catch (RateLimitException $e) { |
| 142 | + echo "Rate limited, retry after {$e->retryAfter} seconds"; |
| 143 | +} catch (AuthenticationException $e) { |
| 144 | + echo "Invalid API key"; |
| 145 | +} catch (SubscriptionRequiredException $e) { |
| 146 | + echo "Subscription required"; |
| 147 | +} |
| 148 | +``` |
| 149 | + |
| 150 | +| Exception | HTTP Status | Description | |
| 151 | +|---|---|---| |
| 152 | +| `ValidationException` | 400 | Invalid input | |
| 153 | +| `AuthenticationException` | 401 | Invalid or missing API key | |
| 154 | +| `SubscriptionRequiredException` | 403 | No active subscription | |
| 155 | +| `NotFoundException` | 404 | No RDAP data found | |
| 156 | +| `RateLimitException` | 429 | Rate limit or quota exceeded | |
| 157 | +| `UpstreamException` | 502 | Upstream RDAP server failure | |
| 158 | + |
| 159 | +All exceptions expose `statusCode`, `errorCode`, and `getMessage()`. `RateLimitException` also has `retryAfter` (int or null). |
| 160 | + |
| 161 | +## Nullable Fields |
| 162 | + |
| 163 | +Fields that may be absent in API responses use nullable types (`?string`, `?int`). Check for null before using: |
| 164 | + |
| 165 | +```php |
| 166 | +if ($domain->dates->expires !== null) { |
| 167 | + echo "Expires: {$domain->dates->expires}"; |
| 168 | +} |
| 169 | + |
| 170 | +// Or use PHP 8's nullsafe operator |
| 171 | +echo $domain->entities->registrant?->name; |
| 172 | +``` |
| 173 | + |
| 174 | +## License |
| 175 | + |
| 176 | +MIT — see [LICENSE](LICENSE). |
0 commit comments