Git Product home page Git Product logo

api-distancep's Introduction

An easy-to-use and free API to calculate distance between multiple CEPs.

How to use

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

Response

{
  "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

Response

{
  "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"
    }
  ]
}



Technologies and APIs used in this project

Stack

  • Node.js
  • Express.js
  • Puppeteer
  • Puppeteer-cluster
  • Redis
  • axios

APIs

  • viacep API
  • google maps (direct query)

Setup

Running Localy

Clone this repository and then run:

npm i
npm start

Deploying to Heroku

How to deploy a puppeteer API to Heroku

Remember to add the "Heroku Redis" add-on

api-distancep's People

Contributors

vnsmoreira avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.