An easy-to-use and free API to calculate distance between multiple CEPs.
GET
https://distancep.herokuapp.com/distance/CEP_ORIGIN/CEP_DESTINATION
const origin = '04335-000';
const destination = '01311000';
const response = await axios.get(`https://api-get-distance.herokuapp.com/distance/${origin}/${destination}`);
const data = response.data;
//do whatever you want
{
"distance": 14.4 //always in km,
"cepsInfo": [
{
"cep": "04335-000",
"logradouro": "Rua Leno",
"complemento": "",
"bairro": "Americanópolis",
"localidade": "São Paulo",
"uf": "SP",
"ibge": "3550308",
"gia": "1004",
"ddd": "11",
"siafi": "7107"
},
{
"cep": "01311-000",
"logradouro": "Avenida Paulista",
"complemento": "até 609 - lado ímpar",
"bairro": "Bela Vista",
"localidade": "São Paulo",
"uf": "SP",
"ibge": "3550308",
"gia": "1004",
"ddd": "11",
"siafi": "7107"
}
]
}
POST
https://distancep.herokuapp.com/distance/
const addresses = ['04335000', '01311-000', '05606010', '23812310'];
const mode = 'driving';
const response = await axios.post(`https://api-get-distance.herokuapp.com/distance/`, {addresses,mode});
const data = response.data;
//do whatever you want
{
"distance": 2.677 //always in km,
"cepsInfo": [
{
"cep": "04335-000",
"logradouro": "Rua Leno",
"complemento": "",
"bairro": "Americanópolis",
"localidade": "São Paulo",
"uf": "SP",
"ibge": "3550308",
"gia": "1004",
"ddd": "11",
"siafi": "7107"
},
{
"cep": "01311-000",
"logradouro": "Avenida Paulista",
"complemento": "até 609 - lado ímpar",
"bairro": "Bela Vista",
"localidade": "São Paulo",
"uf": "SP",
"ibge": "3550308",
"gia": "1004",
"ddd": "11",
"siafi": "7107"
},
{
"cep": "05606-010",
"logradouro": "Avenida Morumbi",
"complemento": "até 1000 - lado par",
"bairro": "Morumbi",
"localidade": "São Paulo",
"uf": "SP",
"ibge": "3550308",
"gia": "1004",
"ddd": "11",
"siafi": "7107"
},
{
"cep": "23812-310",
"logradouro": "Rua São João",
"complemento": "",
"bairro": "São José",
"localidade": "Itaguaí",
"uf": "RJ",
"ibge": "3302007",
"gia": "",
"ddd": "21",
"siafi": "5839"
}
]
}
- Node.js
- Express.js
- Puppeteer
- Puppeteer-cluster
- Redis
- axios
- viacep API
- google maps (direct query)
Clone this repository and then run:
npm i
npm start
How to deploy a puppeteer API to Heroku
Remember to add the "Heroku Redis" add-on