DEV Community

Daniel Igel
Daniel Igel

Posted on

DNS lookups (A/MX/TXT/reverse) as a single JSON endpoint — no resolver wrangling

Doing DNS lookups from app code is more annoying than it should be: dig isn't available everywhere, Node's dns/promises returns a different shape per record type, and you end up writing a switch statement for A vs MX vs TXT vs SOA every single time.

This wraps all of that into one GET. Ask for a single type, or pass type=ALL to get A, AAAA, MX, TXT, NS, CNAME and SOA in one round-trip.

curl --request GET \
  --url 'https://dns-lookup-api3.p.rapidapi.com/api/v1/lookup?domain=example.com&type=ALL' \
  --header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY' \
  --header 'x-rapidapi-host: dns-lookup-api3.p.rapidapi.com'
Enter fullscreen mode Exit fullscreen mode

There's also /api/v1/mx?domain=gmail.com (MX sorted by priority — handy for mail-deliverability checks), /api/v1/reverse?ip=8.8.8.8 for reverse DNS / PTR, and POST /api/v1/lookup/batch for up to 20 domain/type pairs in one call (useful for auditing a list of domains).

Free tier on RapidAPI: https://rapidapi.com/danieligel/api/dns-lookup-api3

Built this because every project re-implemented the same record-type plumbing. What do you reach for today — shelling out to dig, or a library?

Top comments (0)