PHP code example of andreoneres / brasilapi-php

1. Go to this page and download the library: Download andreoneres/brasilapi-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

andreoneres / brasilapi-php example snippets




rasilApi\Client;

$brasilApi = new Client();

$address = $brasilApi->cep()->get('01001000');

$brasilApi->banks()->getList();

$brasilApi->banks()->get(1);

$brasilApi->cep()->get('01001000');

$brasilApi->cepV2()->get('01001000');

$brasilApi->cnpj()->get('00000000000191');

$brasilApi->realtors()->get('76621457000185');

$brasilApi->realtors()->getList();

$brasilApi->cptec()->cities('São Paulo');

$brasilApi->cptec()->cities();

$brasilApi->cptec()->weatherInCapitals();

$brasilApi->cptec()->weatherInAirport('SBGR');

$brasilApi->cptec()->weatherInCity(999);

$brasilApi->cptec()->weatherInCityInXDays(999, 6);

$brasilApi->cptec()->oceanForecastInCity(999);

$brasilApi->cptec()->oceanForecastInCityInXDays(999, 6);

$brasilApi->ddd()->get(77);

$brasilApi->holidays()->fromYear(2022);

$brasilApi->fipe()->brandsByTypeVehicle('caminhoes');

$brasilApi->fipe()->price('001004-9');

$brasilApi->fipe()->referenceTables();

$brasilApi->ibge()->stateCities('BA');

$brasilApi->ibge()->states();

$brasilApi->ibge()->state('BA');

$brasilApi->isbn()->book('9788545702870');

$brasilApi->ncm()->getList();

$brasilApi->ncm()->get('01012100');

$brasilApi->ncm()->search('01012100');

$brasilApi->pix()->participants();

$brasilApi->registerBr()->domain('google.com');

$brasilApi->taxes()->getList();

$brasilApi->taxes()->get('Selic');



rasilApi\Client;
use BrasilApi\Endpoints\Abstracts\Endpoint;

class Hope extends Endpoint
{
    public function getList(): array
    {
        return $this->client->request("/hopes/list");
    }
}

$brasilApi = new Client();

$brasilApi->addEndpoint("hope", Hope::class);

$address = $brasilApi->hope()->getList();

try {
    $address = $brasilApi->cep()->get('01001000');
} catch (BrasilApiException $e) {
    echo $e->getMessage(); // Retorna a mensagem de erro da API
    echo $e->getCode(); // Retorna o código HTTP da API
    echo $e->getErrors(); // Retorna os erros retornados pela API
    echo $e->getRawResponse(); // Retorna a resposta bruta da API
}
bash
composer