How to use the restify.createJsonClient function in restify

To help you get started, we’ve selected a few restify 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 joyent / sdc-docker / lib / wfapi / workflows / push-image.js View on Github external
function pushImageLayers(job, cb) {
    var queue = vasync.queue(processMessage, 5);
    var queueError;

    // For now assume dockerUrl is the URL to the DOCKER_HOST. In this case
    // we parse the URL to obtain the location of the admin host
    var parsedUrl = urlModule.parse(dockerUrl);
    var dockerAdminiUrl = parsedUrl.protocol + '//' + parsedUrl.hostname;
    var dockerAdmin = restify.createJsonClient({
        url: dockerAdminiUrl,
        headers: { 'x-request-id': job.params.req_id }
    });
    var imgapi = new sdcClients.IMGAPI({url: imgapiUrl});

    function processMessage(data, next) {
        if (data.type == 'error') {
            /*
             * Currently WFAPI will add `err.message` and `err.name` to the
             * chain_results. We'll slip our error *code* in using `err.name`.
             */
            queueError = new Error(data.error.message);
            if (data.error.code) {
                queueError.name = data.error.code;
            }
            next();
github joyent / kang / lib / kang.js View on Github external
'protocol': source['protocol'],
	    'hostname': source['host'],
	    'port': source['port']
	});

	options = {
	    'url': url,
	    'retry': false
	};

	for (var k in clientOptions) {
		if (!options.hasOwnProperty(k))
			options[k] = clientOptions[k];
	}

	client = mod_restify.createJsonClient(options);

	client.get(path, function (err, request, response, obj) {
		if (err) {
			callback(err);
			return;
		}

		if (response.statusCode != 200) {
			callback(new Error('response code ' +
			    response.statusCode));
			return;
		}

		callback(null, obj);

		/* This could be reused. */
github joyent / node-smartdc / lib / cloudapi.js View on Github external
if (!options.userAgent) {
        options.userAgent = 'restify/' + RESTIFY_VERSION + ' (' + os.arch() +
            '-' + os.platform() +
            '; v8/' + process.versions.v8 + '; ' +
            'OpenSSL/' + process.versions.openssl + ') ' +
            'node/' + process.versions.node +
            '; node-smartdc/' + VERSION;
    }

    this.token = options.token;

    if (process.env.SDC_TESTING) {
        options.rejectUnauthorized = false;
    }

    this.client = restify.createJsonClient(options);
    this.options = clone(options);

    // Initialize the cache
    if (!options.noCache) {
        this.cacheSize = options.cacheSize || 1000;
        this.cacheExpiry = (options.cacheExpiry || 60) * 1000;
        this.cache = createCache(this.cacheSize);
    }
}
github monbro / opensemanticapi-go-lang / app.js View on Github external
var _ = require("underscore");
var $ = require("jquery");

/** 
 * Objects
 */

// create redis client
var client = redis.createClient();

// create restify server to server http api
var server = restify.createServer();
server.use(restify.bodyParser());

// create restify json client for api requests
var wikipedia = restify.createJsonClient({
  url: 'http://'+config.creds.lang+'.wikipedia.org',
  version: '*'
});

/** 
 * Run
 */

// start api requests with given keyword
wikiSearch('database');

/** 
 * Helper functions
 */

/** 
github joyent / sdc-docker / lib / wfapi / workflows / pull-image-v2.js View on Github external
function pullImageLayersV2(job, cb) {
    var queue = vasync.queue(processMessage, 5);
    var queueError;

    // For now assume dockerUrl is the URL to the DOCKER_HOST. In this case
    // we parse the URL to obtain the location of the admin host
    var parsedUrl = urlModule.parse(dockerUrl);
    var dockerAdminiUrl = parsedUrl.protocol + '//' + parsedUrl.hostname;
    var dockerAdmin = restify.createJsonClient({
        url: dockerAdminiUrl,
        headers: { 'x-request-id': job.params.req_id }
    });
    var imageCreated = false;
    var imgapi = new sdcClients.IMGAPI({url: imgapiUrl});

    function processMessage(data, next) {
        if (data.type == 'error') {
            /*
             * Currently WFAPI will add `err.message` and `err.name` to the
             * chain_results. We'll slip our error *code* in using `err.name`.
             */
            queueError = new Error(data.error.message);
            if (data.error.code) {
                queueError.name = data.error.code;
            }
github pivotaltracker / trissues / test / external / github_spec.js View on Github external
beforeEach(function () {
    client = restify.createJsonClient({
      url: "https://api.github.com/",
      headers: {
        Authorization: "token " + config.auth.github
      }
    });
  });
github pivotaltracker / trissues / app / handlers.js View on Github external
githubissues: function (req, res, next) {
    helpers.log("GET request for importable stories through /githubissues");
    var client = restify.createJsonClient({
      url: "https://api.github.com/",
      headers: {
        Authorization: "token " + config.auth.github
      }
    }),
    filteredLabels = (function () {
      if (config.exclude && config.exclude.labels) {
        return config.exclude.labels.split(/, */);
      } else {
        return [];
      }
    }());
    client.get("/repos/" + config.github.repo + "/issues", function (err, githubReq, githubRes, issues) {
      helpers.log("    Received " + issues.length + " issues from GitHub");

      var responseObj = {
github anders94 / disruptor / lib / peer.js View on Github external
exports.masterStop = function(hostPort, app) {
	console.log('telling '+hostPort+' to tell all known peers to stop '+app);
	var client = restify.createJsonClient({
		url: 'http://'+hostPort,
		agent: false,
		version: '*'
	    });
	client.post('/masterStop', {app: app}, function(err, req, res, data) {
		if (err != null)
		    console.log('Error: Couldn\'t reach '+req._headers.host);
	    });

    }
github joyent / manatee / lib / snapShotter.js View on Github external
function checkHealth(_, cb) {
                if (!self._healthUrl) {
                    return (cb());
                }
                var client = restify.createJsonClient({
                    url: self._healthUrl,
                    version: '*'
                });
                client.get('/ping', function (err, req, res, obj) {
                    log.info({
                        err: err,
                        obj: obj
                    }, 'got manatee sitter status');
                    if (err || (obj && !obj.healthy)) {
                        log.warn({err: err}, 'error fetching manatee status, ' +
                                 'not taking snapshot.');
                        skipSnapshot = true;
                    }
                    return (cb());
                });
            },
github joyent / manatee / lib / adm.js View on Github external
function _watchSitter(_, _cb) {
            _cb = once(_cb);
            var client = restify.createJsonClient({
                url: 'http://' + _.config.ip + ':' +
                    (_.config.postgresPort + 1),
                version: '*'
            });

            var waitCount = 0;
            var lastByte = 0;
            var restoreTry = 1;
            var bar, restore, lastRestore;

            process.stderr.write('Watching sitter for postgres startup  ');
            function checkPostgresStatus() {
                vasync.pipeline({ funcs: [
                    _getClusterStates,
                    _addPostgresStatus,
                    function _getCurrentPeer(subctx, subcb) {