A service for fetching data from an address from a provided zip code.
$ composer require blancohugo/correios
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
}
See how to CONTRIBUTE to this project.