Brasilapi.Cep.API (BrasilAPI v0.1.5)

View Source

Client for BrasilAPI CEP endpoints.

Provides functions to fetch information about Brazilian postal codes (CEP) using the v2 endpoint with multiple providers for fallback.

Summary

Functions

Fetches information about a CEP (postal code) using the v2 endpoint.

Functions

get_by_cep(cep)

@spec get_by_cep(String.t() | integer()) ::
  {:ok, Brasilapi.Cep.Address.t()} | {:error, map()}

Fetches information about a CEP (postal code) using the v2 endpoint.

The v2 endpoint provides geolocation data and uses multiple providers for better reliability. Coordinates are sourced from OpenStreetMap.

Parameters

  • cep - The CEP (postal code) as string or integer. Must be 8 digits.

Examples

iex> Brasilapi.Cep.API.get_by_cep("89010025")
{:ok, %Brasilapi.Cep.Address{
  cep: "89010025",
  state: "SC",
  city: "Blumenau",
  neighborhood: "Centro",
  street: "Rua Doutor Luiz de Freitas Melro",
  service: "viacep",
  location: %{type: "Point", coordinates: %{}}
}}

iex> Brasilapi.Cep.API.get_by_cep("00000000")
{:error, %{status: 404, message: "Not found"}}