An open API service indexing awesome lists of open source software.

https://github.com/felipefrizzo/brazilian-zipcode-api

An API for Brazilian postal codes, where will be available to consult the addresses by zipcode.
https://github.com/felipefrizzo/brazilian-zipcode-api

api-rest correios correios-cep golang postal-codes

Last synced: 6 months ago
JSON representation

An API for Brazilian postal codes, where will be available to consult the addresses by zipcode.

Awesome Lists containing this project

README

          

# πŸ‡§πŸ‡· Brazilian Zipcode API

A fast and extensible API to retrieve Brazilian address information by ZIP code (CEP), with support for multiple storage backends, TTL caching, and third-party provider integration.

---

## ✨ Features

- πŸ” Fetch address data using a Brazilian CEP (zipcode)
- 🧠 Cache layer with configurable TTL using Redis
- πŸ—„οΈ Plug-and-play support for multiple storage backends (e.g. Redis, PostgreSQL, MongoDB)
- ♻️ Automatic cache invalidation and rehydration from third-party APIs (e.g. Correios)
- 🧱 Clean Architecture for scalability and maintainability
- 🚦 Built-in healthcheck endpoint
- πŸ”§ Configurable via `.env` using Viper

---

## πŸ“¦ Installation

```bash
> git clone https://github.com/felipefrizzo/brazilian-zipcode-api.git
> cd brazilian-zipcode-api
> go build -o zipcode-api ./cmd/*
> go run ./cmd/*
```

Server runs on :8080 by default.

## πŸ”§ Configuration

Create a .env file:

```bash
PORT=8080

REDIS_HOST=redis
REDIS_PORT=6379
REDIS_USERNAME=
REDIS_PASSWORD=
REDIS_DB=0

CACHE_TTL_SECONDS=3600
```

## πŸ“˜ API Endpoints

#### Healthcheck

```bash
> curl http://localhost:8080/health
```

#### Get Address by Zipcode

```bash
> curl http://localhost:8080/zipcode/01001000

{
"federative_unit": "PR",
"city": "Cascavel",
"neighborhood": "Centro",
"address_name": "Avenida Brasil",
"complement": "- de 5623 a 6869 - lado Γ­mpar",
"zipcode": "85801000",
}
```

## 🧱 Architecture

- cmd/ β€” Application entry point
- internal/ β€” Domain logic and interfaces
- address/ β€” Domain model + repository interface
- address/redis β€” Redis implementation of address repository
- address/postgres β€” PostgreSQL implementation of address repository
- zipcode/ β€” API handler
- server/ β€” HTTP server initialization
- config/ β€” Viper-based config loader

## πŸ“ˆ Roadmap

1. Correios API integration
1. PostgreSQL and MongoDB support
1. OpenAPI documentation
1. Rate limiting and metrics

## 🀝 Contributing

PRs are welcome. Ensure code is clean, covered by tests, and follows idiomatic Go practices.