JavaScript integration

1 min read

Production-ready fetch patterns for Reverse Contact endpoints.

Minimal fetch helper

const API_BASE_URL = 'https://api.reversecontact.com/v2'

export async function rcRequest(path: string, init: RequestInit = {}) {
  const apiKey = process.env.RC_API_KEY

  if (!apiKey) {
    throw new Error('Missing RC_API_KEY')
  }

  const response = await fetch(`${API_BASE_URL}${path}`, {
    ...init,
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${apiKey}`,
      ...init.headers
    }
  })

  if (!response.ok) {
    throw new Error(`Reverse Contact request failed: ${response.status}`)
  }

  return response.json()
}

Usage

const response = await rcRequest('/fetch/persons', {
  method: 'POST',
  body: JSON.stringify({ url: 'https://social.com/in/example' })
})
console.log(response.data.firstName)

Previous

Company search available fields