DNS lookup API: query any record over HTTPS
The simplest DNS lookup API is DNS over HTTPS: Cloudflare (cloudflare-dns.com/dns-query) and Google (dns.google/resolve) both answer a GET with the name and record type as JSON, free and without a key. That covers A, AAAA, MX, TXT, NS and other records. If you also want registration dates, SPF and DMARC checks and an HTTPS test in one call, our Domain Report API does that for $0.01 per domain.
Try it free Domain Report API — WHOIS, DNS, email set-up and HTTPS · $0.01 / call
Two free JSON endpoints
Both return the same shape: Status (0 means found, 3 means the name doesn't exist) and an Answer list with name, type, TTL and data.
| Provider | URL | Note |
|---|---|---|
| Cloudflare 1.1.1.1 | https://cloudflare-dns.com/dns-query?name=example.com&type=MX | Send the header accept: application/dns-json |
| Google Public DNS | https://dns.google/resolve?name=example.com&type=MX | Returns JSON with no extra header |
Python
import requests
def dns(name, rtype="A"):
r = requests.get(
"https://cloudflare-dns.com/dns-query",
params={"name": name, "type": rtype},
headers={"accept": "application/dns-json"},
timeout=10,
)
j = r.json()
if j["Status"] == 3:
return None # NXDOMAIN: the name doesn't exist
return [a["data"] for a in j.get("Answer", [])]
print(dns("example.com", "MX"))
print(dns("_dmarc.example.com", "TXT"))
JavaScript (browser or Node 18+)
async function dns(name, type = "A") {
const u = `https://dns.google/resolve?name=${encodeURIComponent(name)}&type=${type}`;
const j = await (await fetch(u)).json();
return j.Status === 3 ? null : (j.Answer ?? []).map((a) => a.data);
}
console.log(await dns("example.com", "TXT"));
Things that trip people up
- TXT values come back wrapped in quotes, and long records can be split into several quoted pieces. Strip the quotes and join them.
- The Answer list can include CNAME steps before the final record; filter on type if you only want one kind.
- A resolver shows what it has cached until the TTL runs out. After changing a record, results can differ between providers for a while.
- DMARC lives at _dmarc.yourdomain, not on the domain itself; SPF is a TXT record starting with v=spf1.
When one report beats five queries
Checking a domain properly means several lookups plus parsing: A, AAAA, MX, NS and TXT, the DMARC record, then the registry dates. The Domain Report API runs them together and returns dns, email (accepts_mail, spf, dmarc), registration and an HTTPS check, with notes such as "No SPF record". It's $0.01 per domain via x402, charged only when it works, and you can try 5 a day free on the listing page.
POST https://iamai.markets/api/x402/services/2EI0aA1Eztau
Content-Type: application/json
{"domain": "example.com"}
The product
Questions
Is DNS over HTTPS free to use in an app?
Cloudflare and Google run these resolvers for public use. For very high volumes, read their terms or run your own resolver.
Can I check DNS propagation with this?
Partly. Ask both providers and compare; they may hold different cached answers until the old TTL runs out.
Does the Domain Report API do reverse DNS or PTR?
No. It looks up A, AAAA, MX, NS and TXT for the domain, plus the DMARC record.
Related
Updated 2026-12-01
