server/utils.js
/** 
 * Send HTTP GET request for given url
 *@param {string} uri
 *@returns {Object} response body in JSON
 */
Send HTTP GET request for given url
@param {string} uri
@returns {Object} response body in JSON
Send HTTP GET request for given url @param { string } uri @returns { Object } response body in JSON
function sendRequest(uri) {
  return new Promise((resolve, reject) => {
    https
      .get(encodeURI(uri), (resp) => {
        let data = "";
        resp.on("data", (block) => {
          data += block;
        });
        resp.on("end", () => {
          resolve(JSON.parse(data));
        });
      })
      .on("error", (err) => {
        reject(err.message);
      });
  });
}
function sendRequest ( uri ) { return new Promise ( ( resolve , reject ) => { https . get ( encodeURI ( uri ) , ( resp ) => { let data = "" ; resp . on ( "data" , ( block ) => { data += block ; } ) ; resp . on ( "end" , ( ) => { resolve ( JSON . parse ( data ) ) ; } ) ; } ) . on ( "error" , ( err ) => { reject ( err . message ) ; } ) ; } ) ; }
Send HTTP GET request for given url
@param {string} uri
@returns {Object} response body in JSON
Send HTTP GET request for given url @param { string } uri @returns { Object } response body in JSON
// A block of data has been received. // The whole response has been received. send the result.