index.js
function request(remoteUrl) {
  return new Promise((resolve, reject) => {
    const get = adapters[url.parse(remoteUrl).protocol].get;
    get(remoteUrl, res => {
      const { statusCode } = res;
      const contentType = res.headers['content-type'];
      let rawData = '';

      // If it's not a 200 and not a 404 there's another issue. Allwrite will
      // only return these two statuses.
      if (statusCode !== 200 && statusCode !== 404) {
        const error = new Error('Allwrite: Request Failed.\n' +
                                `Status Code: ${statusCode}`);
        error.code = statusCode;
        return reject(error);
      } else if (!/^application\/json/.test(contentType)) {
        const error = new Error('Allwrite: Invalid content-type.\n' +
                          `Expected application/json but got ${contentType}`);
        return reject(error);
      }

      res.setEncoding("utf8");
      res.on("data", chunk => rawData += chunk);
      res.on("end", () => {
        try {
          resolve(JSON.parse(rawData));
        } catch (e) {
          reject(new Error("Allwrite response parsing error: " + e.message));
        }
      });
    });
  });
}
function request(remoteUrl) {
  return new Promise((resolve, reject) => {
    const get = adapters[url.parse(remoteUrl).protocol].get;
    get(remoteUrl, res => {
      const { statusCode } = res;
      const contentType = res.headers['content-type'];
      let rawData = '';

      // If it's not a 200 and not a 404 there's another issue. Allwrite will
      // only return these two statuses.
      if (statusCode !== 200 && statusCode !== 404) {
        const error = new Error('Allwrite: Request Failed.\n' +
                                `Status Code: ${statusCode}`);
        error.code = statusCode;
        return reject(error);
      } else if (!/^application\/json/.test(contentType)) {
        const error = new Error('Allwrite: Invalid content-type.\n' +
                          `Expected application/json but got ${contentType}`);
        return reject(error);
      }

      res.setEncoding("utf8");
      res.on("data", chunk => rawData += chunk);
      res.on("end", () => {
        try {
          resolve(JSON.parse(rawData));
        } catch (e) {
          reject(new Error("Allwrite response parsing error: " + e.message));
        }
      });
    });
  });
}
function request ( remoteUrl ) { return new Promise ( ( resolve , reject ) => { const get = adapters [ url . parse ( remoteUrl ) . protocol ] . get ; get ( remoteUrl , res => { const { statusCode } = res ; const contentType = res . headers [ 'content-type' ] ; let rawData = '' ; // If it's not a 200 and not a 404 there's another issue. Allwrite will // only return these two statuses. if ( statusCode !== 200 && statusCode !== 404 ) { const error = new Error ( 'Allwrite: Request Failed.\n' + ` ${ statusCode } ` ) ; error . code = statusCode ; return reject ( error ) ; } else if ( ! / ^application\/json / . test ( contentType ) ) { const error = new Error ( 'Allwrite: Invalid content-type.\n' + ` ${ contentType } ` ) ; return reject ( error ) ; } res . setEncoding ( "utf8" ) ; res . on ( "data" , chunk => rawData += chunk ) ; res . on ( "end" , ( ) => { try { resolve ( JSON . parse ( rawData ) ) ; } catch ( e ) { reject ( new Error ( "Allwrite response parsing error: " + e . message ) ) ; } } ) ; } ) ; } ) ; }
Request Allwrite Server.

@param {string} url The url to request.
@return {Promise}
Request Allwrite Server .