EN - Javascript library to search for Brazilian Addresses, Cities and States. PT - Biblioteca javascript para consulta de Endereços, Cidades e Estados
This library is a wrapper for the nfe.io
API to allow easy access to use it.
TODO (for now, check the code)
The nfe.io
API allows to find information about Brazilian addresses.
To use the API, your have to create an account in NFe.io and use your API key.
It is a Base64 encoded key that should be passed in the Authorization header as below:
Authorization: Basic your_api_key
For testing purposes, you can use the following key:
b58801a82418463f961cff952b27baaa
Return all Brazilian states with code
, name
and abbreviation
.
curl http://open.nfe.io/v1/states -H "Authorization: Basic b58801a82418463f961cff952b27baaa"
The response will be like:
[
{
"code": "12",
"abbreviation": "AC",
"name": "Acre"
},
{
"code": "27",
"abbreviation": "AL",
"name": "Alagoas"
},
...
{
"code": "33",
"abbreviation": "RJ",
"name": "Rio de Janeiro"
},
...
{
"code": "35",
"abbreviation": "SP",
"name": "São Paulo"
},
{
"code": "17",
"abbreviation": "TO",
"name": "Tocantins"
}
]
Return all cities that belong to a state.
Let's say we want to list all cities in the state of São Paulo (abbreviation SP)
curl http://open.nfe.io/v1/states/SP/cities -H "Authorization: Basic b58801a82418463f961cff952b27baaa"
The response will be like:
[
{
"code": "3500105",
"name": "Adamantina"
},
...
{
"code": "3550308",
"name": "São Paulo"
},
...
{
"code": "3556701",
"name": "Vinhedo"
},
...
]
Let's say that we have a brazilian postal code (01310-200) and we need to find which city, state and street it represents.
curl http://open.nfe.io/v1/addresses/01310200 -H "Authorization: Basic b58801a82418463f961cff952b27baaa"
The response will be:
{
"postalCode": "01310-200",
"streetSuffix": "Avenida",
"street": "Paulista",
"district": "Bela Vista",
"city": {
"code": "3550308",
"name": "São Paulo"
},
"state": {
"code": "35",
"abbreviation": "SP",
"name": "São Paulo"
}
}