PHPackages                             andredebrito/phpviacep - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. andredebrito/phpviacep

ActiveLibrary[API Development](/categories/api)

andredebrito/phpviacep
======================

Componente PHP para consumo da API VIA CEP (https://viacep.com.br/)

1.0.5(5y ago)125MITPHPPHP ^7.2CI failing

Since May 28Pushed 5y ago1 watchersCompare

[ Source](https://github.com/andredebrito/phpviacep)[ Packagist](https://packagist.org/packages/andredebrito/phpviacep)[ RSS](/packages/andredebrito-phpviacep/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (6)Dependencies (1)Versions (7)Used By (0)

PhpViaCep
=========

[](#phpviacep)

[![Build](https://camo.githubusercontent.com/2e6dc95cea1d99b89d562de5bcf8ff78b675bbffbfcc4c06d3d7859631a59842/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f616e6472656465627269746f2f7068707669616365702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/andredebrito/phpviacep)[![Quality Score](https://camo.githubusercontent.com/601e0196555cebbe4568ce198a58e7bd75c5ec390315ea918f584d0c29b07cdc/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f616e6472656465627269746f2f7068707669616365702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/andredebrito/phpviacep)[![Total Downloads](https://camo.githubusercontent.com/1c27791fc8321d33c8455cc0acba06f5fc9584bca3c7292867bcb1d118867fa4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e6472656465627269746f2f7068707669616365702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/andredebrito/phpviacep)

Este projeto tem por objetivo consumir o webservice ViaCEP. Utilizando o PHP e CURL.

Baseado no webservice . Através dessa classe é possível consultar e obter dados de endereços com retorno nos formatos **JSON**, **XML**, **PIPED** e **QWERT**.

Bibliotecas e tecnlogias utiladas
---------------------------------

[](#bibliotecas-e-tecnlogias-utiladas)

- PHP 7.2
- CURL

Instalação
==========

[](#instalação)

Via composer:

`"andredebrito/phpviacep": "^1.0"`

ou execute:

`composer require andredebrito/phpviacep`

Exemplos de utilização
----------------------

[](#exemplos-de-utilização)

### Pesquisa por CEP

[](#pesquisa-por-cep)

Instancie um novo objeto da classe PhpViaCep e invoque o método `findByCep()` passando o CEP como parâmentro, utilize uma opção de retorno (`json()`, `json_unicode()`, `xml()`, `piped()` ou `querty()`), invoque o método` fetch()` (no exemplo abaixo foi utilizado o método `jsonToObject()` para tornar o response e um objeto). Utilize o método `getResponse()` para exibir os dados.

#### Retorno em Objeto

[](#retorno-em-objeto)

```
require '../vendor/autoload.php;

use AndreDeBrito\PHPViaCep\PhpViaCep;

$findByCep = (new PhpViaCep())->findByCep("01001000")
	      ->json()->fetch()
	      ->jsonToObject();

var_dump($findByCep->getResponse());
```

#### Retorno em XML:

[](#retorno-em-xml)

```
$findByCep = (new PhpViaCep())->findByCep("01001000")
	      ->xml()
	      ->fetch();

var_dump($findByCep->getResponse());
```

#### Retorno em PIPED:

[](#retorno-em-piped)

```
$findByCep = (new PhpViaCep())->findByCep("01001000")
	      ->piped()
	      ->fetch();

var_dump($findByCep->getResponse());
```

#### Retorno em QUERTY:

[](#retorno-em-querty)

```
$findByCep = (new PhpViaCep())->findByCep("01001000")
	      ->querty()
	      ->fetch();

var_dump($findByCep->getResponse());
```

### Pesquisa por Endereço

[](#pesquisa-por-endereço)

Instancie um novo objeto da classe PhpViaCep e invoque o método `findByAddress()` passando UF, Cidade e Endereço como parâmentros, utilize uma opção de retorno (`json()`, `json_unicode()` ou `xml()`), invoque o método `fetch()` (no exemplo abaixo foi utilizado o método `jsonToObject()` para tornar o response e um objeto). Utilize o método `getResponse()` para exibir os dados.

#### Retorno em Objeto

[](#retorno-em-objeto-1)

```
require '../vendor/autoload.php';

use AndreDeBrito\PHPViaCep\PhpViaCep;

$findByAddress = (new PhpViaCep())->findByAddress("SP", "Poá", "Avenida Brasil")
		  ->json()
		  ->fetch()
		  ->jsonToObject();

var_dump($findByAddress->getResponse());
```

#### Retorno em XML

[](#retorno-em-xml-1)

```
$findByAddress = (new PhpViaCep())->findByAddress("SP", "Poá", "Avenida Brasil")
		  ->xml()
		  ->fetch();

var_dump($findByAddress->getResponse());
```

Tratamento de Erros
-------------------

[](#tratamento-de-erros)

Caso o retorno do método `getResponse()` seja **null** utilize o método `getError()` para visualizar o erro.

#### Exemplo

[](#exemplo)

```
if($findByAddress->getError()){
    echo $findByAddress->getError();
}
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

6

Last Release

2166d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/76cc271dccf55d78b3c74f0ce3285380eaa6abc863eb2353a3d0e3e60d60ebc9?d=identicon)[andredebrito](/maintainers/andredebrito)

---

Top Contributors

[![andredebrito](https://avatars.githubusercontent.com/u/60756823?v=4)](https://github.com/andredebrito "andredebrito (3 commits)")

---

Tags

phpviacepconsulta cep

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/andredebrito-phpviacep/health.svg)

```
[![Health](https://phpackages.com/badges/andredebrito-phpviacep/health.svg)](https://phpackages.com/packages/andredebrito-phpviacep)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
