ka2yuki
5/22/2018 - 1:56 PM

Axios HTTP-Requests with Express in Nodejs. 5Way HTTP-RequestsLIST : https://www.twilio.com/blog/2017/08/http-requests-in-node-js.html

Axios HTTP-Requests with Express in Nodejs. 5Way HTTP-RequestsLIST : https://www.twilio.com/blog/2017/08/http-requests-in-node-js.html

const express = require('express')
const app = express()
const axios = require('axios');

app.get('/', (req, res) => {
  axios.get('http://zipcloud.ibsnet.co.jp/api/search?zipcode=2500011')
    .then(response => {
      console.log("res" + response);
      /** // Object loop
       *
        const results = response.data.results[0]
        let ar = [];
        for (const key in results) {
          if (results.hasOwnProperty(key)) {
            ar.push(results[key])
          }
        }
        res.send(ar)
      */
     res.send(response.data.results[0])
      /* //.then(response.hoge) LISTs
        console.log(response.data);
        console.log(response.status);
        console.log(response.statusText);
        console.log(response.headers);
        console.log(response.config);
        // other..
        // https://github.com/axios/axios#response-schema
      */  
    })
    .catch(error => {
      console.log(error);
    });
}) 

app.listen(3000, () => console.log('Example app listening on port 3000!'))