Tutorial

5 DNS Lookup Patterns Every Developer Should Know

From basic A-record queries to advanced SPF validation and mail server discovery - practical patterns for using the APIShard DNS Lookup API in your projects.

A

APIShard Team

March 15, 2026 · 6 min read

5 DNS Lookup Patterns Every Developer Should Know

DNS is one of those technologies developers interact with constantly but rarely think about deeply. The APIShard DNS Lookup API exposes all major record types through a simple HTTP interface - no dig required, no platform-specific libraries, just a clean JSON response.

Here are five patterns that cover the most common real-world scenarios.

API Response Format

The API returns all supported record types in a single response. Example:

{
  "A": ["1.2.3.4"],
  "AAAA": ["2606:4700:4700::1111"],
  "MX": ["mx1.example.com"],
  "NS": ["ns1.example.com", "ns2.example.com"],
  "SOA": null,
  "TXT": [["v=spf1 include:sendgrid.net ~all"], ["google-site-verification=abc123xyz"]],
  "CNAME": ["alias.example.com"],
  "PTR": ["4.3.2.1.in-addr.arpa"],
}

1. Verify Domain Ownership (TXT Records)

Domain verification for services like Google Search Console, SendGrid, or Let's Encrypt relies on TXT records:

curl "https://api.apishard.com/v1/dns-lookup?domain=example.com" \
  -H "x-api-key: $APISHARD_KEY"

Response:

{
  "TXT": [["v=spf1 include:sendgrid.net ~all"], ["google-site-verification=abc123xyz"]],
  ...other record types
}

2. Check Mail Server Configuration (MX Records)

Before sending emails to a domain, verify it actually accepts mail:

async function canReceiveMail(domain: string): Promise<boolean> {
  const res = await fetch(
    `https://api.apishard.com/v1/dns-lookup?domain=${domain}`,
    { headers: { "x-api-key": process.env.APISHARD_KEY! } }
  );
  const data = await res.json();
  return Array.isArray(data.MX) && data.MX.length > 0;
}

3. Validate SPF Records

SPF validation is critical for email deliverability. Look for a TXT record starting with v=spf1:

async function hasSPF(domain: string): Promise<boolean> {
  const res = await fetch(
    `https://api.apishard.com/v1/dns-lookup?domain=${domain}`,
    { headers: { "x-api-key": process.env.APISHARD_KEY! } }
  );
  const { TXT } = await res.json();
  return TXT.some((arr: string[]) => arr.some((v) => v.startsWith("v=spf1")));
}

4. Resolve IP Addresses (A / AAAA Records)

Map a hostname to its IPv4 and IPv6 addresses. Useful for network monitoring or building custom health checks:

curl "https://api.apishard.com/v1/dns-lookup?domain=api.apishard.com" \
  -H "x-api-key: $APISHARD_KEY"

Response:

{
  "A": ["1.2.3.4"],
  "AAAA": ["2606:4700:4700::1111"],
  ...other record types
}

5. Find the Authoritative Name Servers (NS Records)

When debugging propagation issues, knowing which name servers are authoritative for a domain saves a lot of guessing:

const res = await fetch(
  `https://api.apishard.com/v1/dns-lookup?domain=example.com`,
  { headers: { "x-api-key": process.env.APISHARD_KEY! } }
);
const { NS } = await res.json();
// NS: ["ns1.example.com", "ns2.example.com"]

Tip: All DNS Lookup calls cost 1 credit per request. For bulk validation workflows, consider batching queries: first collect all domains, then fan out with Promise.all. This keeps your wall-clock time low even when validating hundreds of domains.

Putting It All Together

Here's a lightweight email domain validator that combines MX and SPF checks:

async function validateEmailDomain(domain: string) {
  const res = await fetch(
    `https://api.apishard.com/v1/dns-lookup?domain=${domain}`,
    { headers: { "x-api-key": process.env.APISHARD_KEY! } }
  );
  const { MX, TXT } = await res.json();
  const hasMX = Array.isArray(MX) && MX.length > 0;
  const hasSPF = TXT.some((arr: string[]) => arr.some((v) => v.startsWith("v=spf1")));
  return { domain, hasMX, hasSPF, valid: hasMX && hasSPF };
}

This pattern works well for sign-up flows where you want to reject obviously invalid email domains before sending a verification email.

Summary

Record TypeUse Case
AIPv4 resolution, health checks
AAAAIPv6 resolution, health checks
MXMail server discovery
NSPropagation debugging
SOAZone authority info
TXTDomain verification, SPF, DKIM
CNAMEAlias resolution
PTRReverse DNS lookup

All record types are available on every APIShard plan. Check the docs for the full reference.