How to use the needle.promise function in needle

To help you get started, we’ve selected a few needle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github expo / exp / src / api.js View on Github external
var url = baseUrl + '/' + encodeURIComponent(methodName) + '/' + encodeURIComponent(JSON.stringify(args));

  // Deprecated
  // if (username && hashedPassword) {
  //   url += '?username=' + encodeURIComponent(username) + '&hashedPassword=' + encodeURIComponent(hashedPassword);
  // }

  //log("url=", url);
  var headers = {
    'Exp-ClientId': await session.clientIdAsync(),
  };
  if (username) {
    headers['Exp-Username'] = username;
  }

  var response = await needle.promise.post(url, null, {headers});
  var ro = response.body;
  // try {
  //   var response = JSON.parse(body);
  // } catch (e) {
  //   var err = new Error("Unparseable response from API server: " + body);
  //   throw err;
  // }
  if (ro.err) {
    throw ApiError(ro.code, ro.err.env, ro.err);
  }
  return ro;
};
github expo / exp / build / api.js View on Github external
var url = baseUrl + '/' + encodeURIComponent(methodName) + '/' + encodeURIComponent(JSON.stringify(args));

  // Deprecated
  // if (username && hashedPassword) {
  //   url += '?username=' + encodeURIComponent(username) + '&hashedPassword=' + encodeURIComponent(hashedPassword);
  // }

  //log("url=", url);
  var headers = {};
  if (username) {
    headers = {
      'Exp-ClientId': yield session.clientIdAsync(),
      'Exp-Username': username };
  }

  var response = yield needle.promise.post(url, null, { headers: headers });
  var ro = response.body;
  // try {
  //   var response = JSON.parse(body);
  // } catch (e) {
  //   var err = new Error("Unparseable response from API server: " + body);
  //   throw err;
  // }
  if (ro.err) {
    throw ApiError(ro.code, ro.err.env, ro.err);
  }
  return ro;
});
github expo / exp / src / commands / bundle.js View on Github external
var outStream = process.stdout;
    if (filepath) {
      outStream = fs.createWriteStream(filepath);
    }

    var url = await urlUtil.mainBundleUrlAsync(uo);
    log("Requesting bundle from", url, "...");
    if (filepath) {
      log("Saving to", filepath);
    }

    try {

      simpleSpinner.start();
      try {
        var response = await needle.promise.get(url);
      } catch (e) {
        throw CommandError('NO_RESPONSE', env, "Server didn't respond.\n" + e.message);
      } finally {
        simpleSpinner.stop();
      }

      if (response.statusCode != 200) {
        if (_.isObject(response.body)) {
          var errInfo = response.body;
          log.error(errInfo.type, errInfo.message);
          console.error(errInfo.snippet);
          if (errInfo.type) {
            throw CommandError(errInfo.type, env, "Error in generating bundle");
          }
        } else {
          log.error("Uknown Error:", response.body);
github expo / exp / build / commands / bundle.js View on Github external
var outStream = process.stdout;
    if (filepath) {
      outStream = fs.createWriteStream(filepath);
    }

    var url = yield urlUtil.mainBundleUrlAsync(uo);
    log('Requesting bundle from', url, '...');
    if (filepath) {
      log('Saving to', filepath);
    }

    try {

      simpleSpinner.start();
      try {
        var response = yield needle.promise.get(url);
      } catch (e) {
        throw CommandError('NO_RESPONSE', env, 'Server didn\'t respond.\n' + e.message);
      } finally {
        simpleSpinner.stop();
      }

      if (response.statusCode != 200) {
        throw CommandError('BAD_RESPONSE', env, 'Non-200 response: ' + response.statusCode + ': ' + response.statusMessage);
      }
    } catch (e) {
      throw CommandError('FAILED_TO_DOWNLOAD_BUNDLE', env, 'Failed to download bundle; did you run `exp start`?\n' + e);
    }

    yield outStream.promise.write(response.body);
    var bytes = response.body.length;
    if (filepath) {
github expo / exp / src / urlUtil.js View on Github external
async function testUrlAsync(url) {
  var httpUrl = url.replace(/^exp:\/\//, 'http://');
  var response = await needle.promise.get(httpUrl);
  if (!(response.statusCode == 200)) {
    throw new Error("Problem reading from URL " + httpUrl + "\nstatusCode=" + response.statusCode);
  }
  return url;
}

needle

The leanest and most handsome HTTP client in the Nodelands.

MIT
Latest version published 3 months ago

Package Health Score

85 / 100
Full package analysis