Skip to content

blancohugo/correios

Repository files navigation

Correios zip code query with PHP

Latest version CircleCI Code Coverage Download count

A service for fetching data from an address from a provided zip code.

Installation

$ composer require blancohugo/correios

How-to

See the example below of how to implement a search for address data:

<?php

require 'vendor/autoload.php';

use BlancoHugo\Correios\Zipcode;
use BlancoHugo\Correios\Client;
use BlancoHugo\Correios\Exception;

$client = new Client();
$address = $client->query(new Zipcode('01311-929'));

The client class uses exceptions for data treatments. Make sure your code will have a treatment for the following situations:

<?php

try {
    $address = $client->query(new Zipcode('01311-929'));
} catch (Exception\InvalidZipcodeException $e) {
    // Invalid zipcode
} catch (Exception\ZipcodeNotFoundException $e) {
    // Address data not found
} catch (Exception\UnexpectedResponseException $e) {
    // Unexpected response from SIGEP
}

Contributing

See how to CONTRIBUTE to this project.

About

A service for fetching data from an address from a provided zip code.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages