CPFHub.io

Consultar CPF com Swift

Consulte CPF com Swift usando URLSession nativo. Sem dependências externas.

Integrando com Cursor, Lovable, v0 ou outra IA?

Copie o prompt de integração e cole direto no seu assistente de IA - ele saberá exatamente como usar a API.

Abrir no Cursor

Exemplo

Swift
import Foundation

var request = URLRequest(url: URL(string: "https://api.cpfhub.io/cpf/12345678909")!)
request.setValue("SUA_API_KEY", forHTTPHeaderField: "x-api-key")
let (data, _) = try await URLSession.shared.data(for: request)
let json = try JSONSerialization.jsonObject(with: data) as! [String: Any]
print(json)

Substitua SUA_API_KEY pela sua chave de API em app.cpfhub.io. A chave deve ficar no backend — nunca em apps distribuídos pela App Store.

Resposta

A API retorna um objeto JSON com os dados do CPF consultado:

JSON
{
  "success": true,
  "data": {
    "cpf": "12345678909",
    "name": "Fulano de Tal",
    "nameUpper": "FULANO DE TAL",
    "gender": "M",
    "birthDate": "15/06/1990",
    "day": 15,
    "month": 6,
    "year": 1990
  }
}

Próximos passos