|
| 1 | +# RDAP API Node.js SDK |
| 2 | + |
| 3 | +[](https://www.npmjs.com/package/rdapapi) |
| 4 | +[](https://www.npmjs.com/package/rdapapi) |
| 5 | +[](https://opensource.org/licenses/MIT) |
| 6 | + |
| 7 | +Official Node.js SDK for the [RDAP API](https://rdapapi.io) — look up domains, IP addresses, ASNs, nameservers, and entities via the RDAP protocol. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +```bash |
| 12 | +npm install rdapapi |
| 13 | +``` |
| 14 | + |
| 15 | +## Quick start |
| 16 | + |
| 17 | +```typescript |
| 18 | +import { RdapClient } from "rdapapi"; |
| 19 | + |
| 20 | +const client = new RdapClient("your-api-key"); |
| 21 | + |
| 22 | +// Domain lookup |
| 23 | +const domain = await client.domain("google.com"); |
| 24 | +console.log(domain.registrar.name); // "MarkMonitor Inc." |
| 25 | +console.log(domain.dates.expires); // "2028-09-14T04:00:00Z" |
| 26 | +console.log(domain.nameservers); // ["ns1.google.com", ...] |
| 27 | + |
| 28 | +// IP address lookup |
| 29 | +const ip = await client.ip("8.8.8.8"); |
| 30 | +console.log(ip.name); // "GOGL" |
| 31 | +console.log(ip.cidr); // ["8.8.8.0/24"] |
| 32 | + |
| 33 | +// ASN lookup |
| 34 | +const asn = await client.asn(15169); |
| 35 | +console.log(asn.name); // "GOOGLE" |
| 36 | + |
| 37 | +// Nameserver lookup |
| 38 | +const ns = await client.nameserver("ns1.google.com"); |
| 39 | +console.log(ns.ipAddresses.v4); // ["216.239.32.10"] |
| 40 | + |
| 41 | +// Entity lookup |
| 42 | +const entity = await client.entity("GOGL"); |
| 43 | +console.log(entity.name); // "Google LLC" |
| 44 | +console.log(entity.autnums[0].handle); // "AS15169" |
| 45 | + |
| 46 | +client.close(); |
| 47 | +``` |
| 48 | + |
| 49 | +## Bulk domain lookups |
| 50 | + |
| 51 | +Look up multiple domains in a single request (Pro and Business plans). Up to 10 domains per call, with concurrent upstream fetches: |
| 52 | + |
| 53 | +```typescript |
| 54 | +const result = await client.bulkDomains(["google.com", "github.com", "invalid..com"], { |
| 55 | + follow: true, |
| 56 | +}); |
| 57 | + |
| 58 | +console.log(result.summary); // { total: 3, successful: 2, failed: 1 } |
| 59 | + |
| 60 | +for (const r of result.results) { |
| 61 | + if (r.status === "success" && r.data) { |
| 62 | + console.log(`${r.data.domain}: ${r.data.registrar.name}`); |
| 63 | + } else { |
| 64 | + console.log(`${r.domain}: ${r.error}`); |
| 65 | + } |
| 66 | +} |
| 67 | +``` |
| 68 | + |
| 69 | +Each domain counts as one request toward your monthly quota. Starter plans receive a `SubscriptionRequiredError` (403). |
| 70 | + |
| 71 | +## Registrar follow-through |
| 72 | + |
| 73 | +For thin registries like `.com` and `.net`, the registry only returns basic registrar info. Use `follow: true` to follow the registrar's RDAP link and get richer contact data: |
| 74 | + |
| 75 | +```typescript |
| 76 | +const domain = await client.domain("google.com", { follow: true }); |
| 77 | +console.log(domain.entities.registrant?.organization); // "Google LLC" |
| 78 | +console.log(domain.entities.registrant?.email); // "registrant@google.com" |
| 79 | +``` |
| 80 | + |
| 81 | +## Error handling |
| 82 | + |
| 83 | +```typescript |
| 84 | +import { RdapClient, NotFoundError, RateLimitError, AuthenticationError } from "rdapapi"; |
| 85 | + |
| 86 | +const client = new RdapClient("your-api-key"); |
| 87 | + |
| 88 | +try { |
| 89 | + const domain = await client.domain("nonexistent.example"); |
| 90 | +} catch (err) { |
| 91 | + if (err instanceof NotFoundError) { |
| 92 | + console.log("Domain not found"); |
| 93 | + } else if (err instanceof RateLimitError) { |
| 94 | + console.log(`Rate limited. Retry after ${err.retryAfter}s`); |
| 95 | + } else if (err instanceof AuthenticationError) { |
| 96 | + console.log("Invalid API key"); |
| 97 | + } |
| 98 | +} |
| 99 | +``` |
| 100 | + |
| 101 | +All exceptions inherit from `RdapApiError` and include `statusCode`, `error`, and `message` properties. |
| 102 | + |
| 103 | +| Exception | HTTP Status | When | |
| 104 | +| --------------------------- | ----------- | ---------------------------- | |
| 105 | +| `ValidationError` | 400 | Invalid input format | |
| 106 | +| `AuthenticationError` | 401 | Missing or invalid API key | |
| 107 | +| `SubscriptionRequiredError` | 403 | No active subscription | |
| 108 | +| `NotFoundError` | 404 | No RDAP data found | |
| 109 | +| `RateLimitError` | 429 | Rate limit or quota exceeded | |
| 110 | +| `UpstreamError` | 502 | Upstream RDAP server error | |
| 111 | + |
| 112 | +## Configuration |
| 113 | + |
| 114 | +```typescript |
| 115 | +const client = new RdapClient("your-api-key", { |
| 116 | + baseUrl: "https://rdapapi.io/api/v1", // default |
| 117 | + timeout: 30_000, // milliseconds, default |
| 118 | +}); |
| 119 | +``` |
| 120 | + |
| 121 | +## TypeScript |
| 122 | + |
| 123 | +The SDK is written in TypeScript with full type definitions. All response types are exported: |
| 124 | + |
| 125 | +```typescript |
| 126 | +import type { DomainResponse, IpResponse, AsnResponse } from "rdapapi"; |
| 127 | +``` |
| 128 | + |
| 129 | +## Requirements |
| 130 | + |
| 131 | +- Node.js 20 or later |
| 132 | +- An API key from [rdapapi.io](https://rdapapi.io/register) |
| 133 | + |
| 134 | +## Links |
| 135 | + |
| 136 | +- [API Documentation](https://rdapapi.io/docs) |
| 137 | +- [Get an API Key](https://rdapapi.io/register) |
| 138 | +- [OpenAPI Spec](https://rdapapi.io/openapi.yaml) |
| 139 | +- [Pricing](https://rdapapi.io/pricing) |
| 140 | + |
| 141 | +## License |
| 142 | + |
| 143 | +MIT |
0 commit comments