DNS Lookup API: A Developer's Guide to Programmatic DNS Queries
How to query A, AAAA, MX, NS, TXT, CAA, SRV, and SOA DNS records in a single API call. Practical examples for email validation, security research, and infrastructure monitoring.
DNS Lookup API: A Developer's Guide to Programmatic DNS Queries
DNS records are the backbone of internet infrastructure, but querying them programmatically is surprisingly tedious. You need dig or nslookup for ad-hoc checks, a DNS resolver library for code, and separate calls for each record type. A DNS Lookup API collapses all of that into a single HTTP request that returns structured JSON.
Why developers need a DNS API
Common use cases where programmatic DNS lookup beats manual tools:
- Email validation pipelines: Check MX records to verify a domain can receive mail before sending. A domain without MX records will bounce.
- Security research: Enumerate TXT records for SPF, DKIM, and DMARC policies. Check NS records to map infrastructure. Resolve CNAME chains to detect domain spoofing.
- Infrastructure monitoring: Track SOA serial numbers across nameservers to detect propagation delays. Verify SRV records for service discovery.
- Certificate management: CAA records control which certificate authorities are allowed to issue certificates for a domain. Querying them programmatically helps automate certificate workflows.
Querying all record types in one call
The traditional approach requires separate calls per record type:
dig +short MX github.com
dig +short TXT github.com
dig +short NS github.com
A unified DNS API returns everything in one structured response:
curl -X POST "https://theglitchstore.com/api/secure-proxy?api=dns-lookup" \
-H "x-api-key: gstore_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"domain": "github.com",
"types": ["A", "AAAA", "MX", "NS", "TXT", "CAA"]
}'
The response is structured JSON with each record type as a key:
{
"domain": "github.com",
"records": {
"A": ["20.205.243.166"],
"MX": [{"priority": 0, "exchange": "smtp.github.com."}],
"NS": ["ns-1707.awsdns-21.co.uk.", "ns-421.awsdns-52.com."],
"TXT": ["\"v=spf1 include:spf.github.com -all\""],
"CAA": [{"flag": 0, "tag": "issue", "value": "digicert.com"}]
}
}
Record types explained
| Type | What it returns | Why developers query it |
|---|---|---|
| A | IPv4 address | Resolve a domain to its server |
| AAAA | IPv6 address | IPv6 connectivity checks |
| MX | Mail exchange servers | Verify email deliverability |
| NS | Authoritative nameservers | Infrastructure mapping |
| TXT | Arbitrary text records | SPF, DKIM, DMARC, domain verification |
| CNAME | Canonical name | Redirect chains, alias resolution |
| SOA | Start of authority | Zone serial, refresh intervals |
| SRV | Service records | Service discovery (SIP, XMPP, AD) |
| CAA | Certification authority | Which CAs can issue certs |
| PTR | Reverse DNS | IP-to-hostname verification |
Practical example: email deliverability check
Before adding an email address to your database, verify the domain has valid MX records:
async function canReceiveEmail(email) {
const domain = email.split('@')[1];
const res = await fetch('https://theglitchstore.com/api/secure-proxy?api=dns-lookup', {
method: 'POST',
headers: {
'x-api-key': process.env.GLITCH_STORE_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({ domain, types: ['MX', 'TXT'] }),
});
const data = await res.json();
const hasMX = data.records.MX && data.records.MX.length > 0;
const spf = data.records.TXT?.find(t => t.includes('v=spf1'));
return { canReceive: hasMX, hasSpf: Boolean(spf) };
}
This catches domains that will silently bounce and flags those without SPF records (more likely to be flagged as spam).
Pricing
DNS lookups cost 0.5 credits per call ($0.005). At 1 credit = $0.01, 100 credits costs $1 and covers 200 DNS queries across all record types. Credits never expire.
Sign up free at theglitchstore.com to get 100 trial credits and test the DNS Lookup API in the playground.