add cep and cnpj to api

This commit is contained in:
2025-12-28 18:48:55 -03:00
parent 8b81d5c245
commit f7d1854309
7 changed files with 185 additions and 151 deletions

View File

@@ -0,0 +1,23 @@
import { data } from 'react-router'
import type { Route } from './+types/route'
export async function loader({ params }: Route.LoaderArgs) {
const r = await fetch(`https://opencep.com/v1/${params.cep}`, {
method: 'GET'
})
if (!r.ok) {
throw new Response(await r.text(), { status: r.status })
}
const json = (await r.json()) as any
return data({
postcode: json.cep.replace(/\D/g, ''),
address1: json.logradouro,
address2: json.complemento,
neighborhood: json.bairro,
city: json.localidade,
state: json.uf
})
}