Empacotador da api ViaCep para projeto JS
npm install node-viacep


A wrapper to work with the ViaCep Web API.
This library relies on Fetch API. And this API is supported in the following browsers.
!Chrome | !Firefox | !Opera | !Safari | !IE |
--- | --- | --- | --- | --- |
39+ ✔ | 42+ ✔ | 29+ ✔ | 10.1+ ✔ | Nope ✘ |
This library depends on fetch to make requests to the Spotify Web API. For environments that don't support fetch, you'll need to provide a polyfill to browser or polyfill to Node.
more info on how to use node-fech.
``sh`
$ npm install node-viacep --save
`js
// to import a specific method
import ViaCep from 'node-viacep';
const viacep = new ViaCep({
type: 'json'
})
`
`js
const ViaCep = require('node-viacep').default;
const viacep = new ViaCep({
type: 'json'
})
`
`html
`
After that the library will be available to the Global as ViaCep. Follow an example:
`js
import ViaCep from 'node-viacep';
global.fetch = require('node-fetch');
const viacep = new ViaCep({
type: 'json'
})
const address = viacep.zipCod.getZip('29010250');
address
.then(data => data.json())
.then(data => console.log(data));
`
JSON
`js
//use in zipCod and address methods
const viacep = new ViaCep({
type: 'json'
})
//return
{ cep: '29010-250',
logradouro: 'Rua Alberto de Oliveira Santos',
complemento: '',
bairro: 'Centro',
localidade: 'Vitória',
uf: 'ES',
unidade: '',
ibge: '3205309',
gia: ''
}
`
XML
`js
//use in zipCod and address methods
const viacep = new ViaCep({
type: 'xml'
})
//return
`
PIPED
`js
//just use in zipCod methods
const viacep = new ViaCep({
type: 'piped'
})
//return
cep:29010-250|logradouro:Rua Alberto de Oliveira Santos|complemento:|bairro:Centro|localidade:Vitória|uf:ES|unidade:|ibge:3205309|gia:
`
QUERTY
`js
//just use in zipCod methods
const viacep = new ViaCep({
type: 'json'
})
//return
cep=29010-250&logradouro=Rua+Alberto+de+Oliveira+Santos&complemento=&bairro=Centro&localidade=Vit%C3%B3ria&uf=ES&unidade=&ibge=3205309&gia=
`
> Follow the methods that the library provides.
> Search for informations about zipcode with provided query. Test in ViaCep Api.
Arguments
| Argument | Type | Options |
|----------|---------|-------------------|
|query |string | 'Any search query'|
Example
> this method returns the type specified in the constructor
`js`
viacep.zipCod.getZip('29010250')
.then(data => data.text())
.then(data => console.log(data));
> Search for informations about zipcode with provided query. Test in ViaCep Api.
Arguments
| Argument | Type | Options |
|----------|---------|-------------------|
|query |string | 'Any search query'|
Example
> this method returns a json
`js`
viacep.zipCod.getJson('29010250')
.then(data => data.json())
.then(data => console.log(data));
> Search for informations about zipcode with provided query. Test in ViaCep Api.
Arguments
| Argument | Type | Options |
|----------|---------|-------------------|
|query |string | 'Any search query'|
Example
> this method returns an xml
`js`
viacep.zipCod.getXml('29010250')
.then(data => data.text())
.then(data => console.log(data));
> Search for informations about zipcode with provided query. Test in ViaCep Api.
Arguments
| Argument | Type | Options |
|----------|---------|-------------------|
|query |string | 'Any search query'|
Example
> this method returns a piped
`js`
viacep.zipCod.getPiped('29010250')
.then(data => data.text())
.then(data => console.log(data));
> Search for informations about zipcode with provided query. Test in ViaCep web API.
Arguments
| Argument | Type | Options |
|----------|---------|-------------------|
|query |string | 'Any search query'|
Example
> this method returns a querty
`js`
viacep.zipCod.getQuerty('29010250')
.then(data => data.text())
.then(data => console.log(data));
> Search for informations about some address with all id's. Test in ViaCep web APi.
Arguments
| Argument | Type | Options |
|----------|---------|---------------------------------|
|ids |Array of strings | ['UF', 'city', 'street']|
Example
> this method returns a json
`js`
viacep.address.getJson('ES', 'vitoria', 'alberto de')
.then(data => data.json())
.then(data => console.log(data));
> Search for informations about some address with all id's.
Test in ViaCep web APi..
Arguments
| Argument | Type | Options |
|----------|-------------------|-------------------------|
|ids |Array of strings | ['UF', 'city', 'street']|
Example
> this method returns an xml
`js``
viacep.address.getXml('ES', 'vitoria', 'alberto de')
.then(data => data.text())
.then(data => console.log(data));
We use SemVer for versioning. For the versions available, see the tags on this repository.
| !Adriano Reis|
|:---------------------:|
| Adriano Reis |
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details