How to use the needle.request 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 prey / prey-node-client / lib / agent / actions / fileretrieval / index.js View on Github external
exports.start = function(options, cb) {
  
  var url = UPLOAD_SERVER + '?uploadID=' + options.file_id;
  // Make a call to get the last byte processed by the upload server
  // in order to resume the upload from that position.
  needle.request('get', url, null, function(err, res) {
    if (err) {
      console.log(err);
      return;
    }
    if (res.statusCode == 404) {
      files.del(options.file_id);
      return;
    }
    var data = JSON.parse(res.body);
    var file_status = JSON.parse(res.body).Status
    options.total = data.Total;

    if (file_status == 0 || file_status == 4) { // File in progress(0) or Pending(4)  
      files.exist(options.file_id, function(err, exist) {
        if (!exist) {
          options.resumable = false;
github prey / prey-node-client / lib / agent / actions / fileretrieval / upload.js View on Github external
function retrieve_file(file, cb) {
  if (file.resumable == 'true') {
    console.log("Resumable file:", file.id);
    var url = UPLOAD_SERVER + '?uploadID=' + file.id;
    // Make a call to get the last byte processed by the upload server
    // in order to resume the upload from that position.
    needle.request('get', url, null, function(err, res) {
      if (err) {
        console.log(err);
        cb(err);
        return;
      }
      var data = JSON.parse(res.body);

      file.total = data.Total;
      get_file(file, cb);
    })
    return;
  }
  get_file(file, cb);
}
github prey / prey-node-client / lib / agent / transports / http / index.js View on Github external
exports.request = function request(method, url, data, opts, cb) {
  needle.request(method, url, data, opts, function(err, resp) {
    if (err) hooks.trigger('error', err);

    // hooks.trigger('response', err, resp, data);
    cb && cb(err, resp);
  })
}
github feup-infolab / dendro / src / plugins / dendro_recommender / package / connection.js View on Github external
if(self.config.network.port != null)
    {
        fullUrl = fullUrl + ":" + self.config.network.port;
    }

    fullUrl = fullUrl +  "/about";

    var needle = require('needle');

    if(self.config.debug.check_connection_output)
    {
        console.log("Checking connection to Dendro Recommender instance at: " + fullUrl);
    }

    needle.request("get",
        fullUrl,
        null,
        {
            accept: "application/json"
        },
        function(err, response, body)
        {
            if(!err)
            {
                if(body.result == "ok" && body.message == "Dendro Recommender Online")
                {
                    if(self.config.debug.check_connection_output)
                    {
                        console.log("SUCCESS connecting to Dendro Recommender instance at: " + fullUrl);
                    }
github wazuh / wazuh-kibana-app / server / wazuh-monitoring.js View on Github external
server.log([blueWazuh, 'Wazuh agents monitoring', 'error'], 'You must provide a max size');
		}

		var payload = {
			'offset': offset ? offset : 0,
			'limit': (250 < maxSize) ? 250 : maxSize
		};

		var options = {
			headers: { 'wazuh-app-version': appVersion },
			username: apiEntry.user,
			password: apiEntry.password,
			rejectUnauthorized: !apiEntry.insecure
		};

		needle.request('get', getPath(apiEntry) + '/agents', payload, options, function (error, response) {
			if (!error && !response.error && response.body.data.items) {
				agentsArray = agentsArray.concat(response.body.data.items);
				if ((payload.limit + payload.offset) < maxSize) {
					checkStatus(apiEntry, response.body.data.totalItems, payload.limit + payload.offset);
				} else {
					saveStatus();
				}
			} else {
				server.log([blueWazuh, 'Wazuh agents monitoring', 'error'], 'Can not access Wazuh API');
				return;
			}
		});
	};
github opentable / mercury / src / services / smartling.js View on Github external
authenticate(options, (err, accessToken) => {
      if (err) {
        return next(err);
      }

      const queryString = {
        fileUri: options.fileUri
      };

      const reqDetails = {
        headers: { Authorization: `Bearer ${accessToken}` }
      };

      needle.request('get', `${BASE_URL}/files-api/v2/projects/${options.projectId}/file/status`, queryString, reqDetails, (err, response, body) => {
        const status = _.get(body, 'response.data');

        if (err || !status || response.statusCode !== 200) {
          return next(new Error(`Error when retrieving translation status for ${options.fileUri}`));
        }

        next(null, status);
      });
    });
  },
github duerig / appnet.js / dist / appnet.js View on Github external
var deferred = Q.defer();

	var options = jQuery.extend({ compressed: true }, options);

	if (options.dataType === 'json')
	{
		options.json = true;
	}

	if (options.dataType === 'multipart')
	{
		options.multipart = true;
	}

	needle.request(options.type, options.url, options.data, options, function (error, response, body)
	{
		if (error || response.statusCode !== 200)
		{
		deferred.reject(body);
		}
		else
		{
		deferred.resolve(body);
		}
	});

	return deferred.promise;
	};
github itchio / itch / appsrc / promised / needle.ts View on Github external
export function request (method: INeedleMethod, uri: string, data: any, options: any,
                         callback: INeedleCallback): INeedleRequest {
  if (isOffline()) { return closeConnection(callback); }
  return needle.request(method, uri, data, withProxy(options), callback);
}
github duerig / appnet.js / src / base.js View on Github external
var deferred = Q.defer();

    var options = jQuery.extend({ compressed: true }, options);

    if (options.dataType === 'json')
    {
      options.json = true;
    }

    if (options.dataType === 'multipart')
    {
      options.multipart = true;
    }

    needle.request(options.type, options.url, options.data, options, function (error, response, body)
    {
      if (error || response.statusCode !== 200)
      {
        deferred.reject(body);
      }
      else
      {
        deferred.resolve(body);
      }
    });

    return deferred.promise;
  };

needle

The leanest and most handsome HTTP client in the Nodelands.

MIT
Latest version published 2 months ago

Package Health Score

85 / 100
Full package analysis