How to use node-rest-client - 10 common examples

To help you get started, we’ve selected a few node-rest-client 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 oracle / content-and-experience-toolkit / react-starter-sites / bin / serverUtils.js View on Github external
var typesPromise = new Promise(function (resolve, reject) {
		if (!server || !server.url || !server.username || !server.password) {
			console.log('ERROR: no server is configured');
			return resolve({});
		}
		var client = new Client({
			user: server.username,
			password: server.password
		});
		var url = server.url + '/content/management/api/v1/types?limit=99999';
		client.get(url, function (data, response) {
			var types = [];
			if (response && response.statusCode === 200) {
				types = data && data.items;
				return resolve({
					types: types
				});
			} else {
				// console.log('status=' + response.statusCode + ' err=' + err);
				console.log('ERROR: failed to query content types');
				return resolve({});
			}
github Duke-Translational-Bioinformatics / duke-data-service / docker / builds / dredd / dredd_scripts / tools.js View on Github external
uploadSwiftChunk = function(request_method, request_path, chunk_content) {
  var request = new Promise();
  var client = new Client();
  var args = {
    // "headers": { "Content-Type": "application/json", "Authorization": process.env. },
    "data": chunk_content
  };
  console.log('Upload Swift chunk request path: '.concat(request_path));
  client.registerMethod("apiMethod", request_path, request_method);
  client.methods.apiMethod(args, function(data, response) {
    console.log('Upload Swift chunk HTTP status code: '.concat(response.statusCode));
    if (!(_.contains([200, 201], response.statusCode))) {
        console.log('The Swift chunk upload failed - '.concat(response.statusCode).concat(': '));
        console.log(request_path);
        console.log(JSON.stringify(data));
        // console.log(response);
    }
    request.resolve(data);
  });
github Duke-Translational-Bioinformatics / duke-data-service / docker / builds / dredd / dredd_scripts / 99_learnclient.js View on Github external
function uploadSwiftChunk(request_method, request_path, chunk_content) {
  var request = new Promise();
  var client = new Client();
  var args = {
    // "headers": { "Content-Type": "application/json", "Authorization": process.env. },
    "data": chunk_content
  };
  console.log('Upload Swift chunk request path: '.concat(request_path));
  client.registerMethod("apiMethod", request_path, request_method);
  client.methods.apiMethod(args, function(data, response) {
    console.log('Upload Swift chunk HTTP status code: '.concat(response.statusCode));
    if (!(_.contains([200, 201], response.statusCode))) {
        console.log('The Swift chunk upload failed - '.concat(response.statusCode).concat(': '));
        console.log(request_path);
        console.log(JSON.stringify(data));
        // console.log(response);
    }
    request.resolve(data);
  });
github ibm-watson-iot / iot-nodejs / samples / oldstuff / cognitive / app.js View on Github external
// Add a simple route for static content served from './public'
app.use( "/", express.static("public") );

// Create a server
var httpServer = http.createServer(app);
var port = process.env.VCAP_APP_PORT || 8080;

// Use application-level middleware for common functionality
app.use(require('morgan')('combined'));
app.use(require('cookie-parser')());
app.use(require('body-parser').urlencoded({ extended: true }));
app.use(require('express-session')({ secret: 'keyboard cat', resave: true, saveUninitialized: true }));

// Set up the client for sending data to Node-RED
var Client = require('node-rest-client').Client;
var client = new Client();


/*
 * Begin set-up for the Node-RED directory.  There are a few key differences between a vanilla install of Node-RED
 * and embedding Node-RED in an Express app.  The settings variable has similar details to bluemix-settings.js.
 */

var settings = {
    httpAdminRoot:"/red",
    httpNodeRoot: "/",
    mqttReconnectTime: 4000,
    serialReconnectTime: 4000,
    debugMaxLength: 1000,

    // Basic flow protection, password is password using bcrypt algorithim 
    /*adminAuth: {
github applebaum / open-cryptofolio / server.js View on Github external
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var app = express();
var http = require('http');
var fs = require('fs');
var url = require('url');

// setup node-rest-client dependeices
var Client = require('node-rest-client').Client;
var client = new Client();

// setup socket.io dependencies
var io = require('./io');
import ioClient from 'socket.io-client';

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hjs');

// uncomment after placing your favicon in /public
app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
github Colored-Coins / coloredcoinsd / coluutils.js View on Github external
var errors = require('cc-errors')
    var assetIdencoder = require('cc-assetid-encoder')
    var _ = require('lodash')
    var rsa = require('node-rsa')
    var session = require('continuation-local-storage').getNamespace(config.serverName)
    var findBestMatchByNeededAssets = require('./modules/findBestMatchByNeededAssets')

    

    var creds = {}
    creds.AWSAKI = process.env.AWSAKI
    creds.AWSSSK = process.env.AWSSSK

    var CC_TX_VERSION = 0x02

    var client = new Client()

    var rpcclient = new rpc.Client(config.bitcoind)

    function coluutils() {
       //client.registerMethod("getaddressutxos", config.blockexplorer.url + "/api/getaddressutxos?address=${address}", "GET")
       client.registerMethod("getaddressutxos", config.blockexplorer.url + "/api/getaddressesutxos", "POST")
       client.registerMethod("getassetholders", config.blockexplorer.url + "/api/getassetholders?assetId=${assetid}&confirmations=${minconf}", "GET")
       client.registerMethod("getassetinfo", config.blockexplorer.url + "/api/getassetinfo", "GET")
       client.registerMethod("gettransaction", config.blockexplorer.url + "/api/gettransaction?txid=${txid}", "GET")
       client.registerMethod("getutxo", config.blockexplorer.url + "/api/getutxos", "POST")
       client.registerMethod("broadcasttx", config.blockexplorer.url + "/api/transmit", "POST")
      // client.registerMethod("getutxo", config.blockexplorer.url + "/api/getutxo?txid=${txid}&index=${index}", "GET")
       client.registerMethod("preparsetx", config.blockexplorer.url + "/api/parsetx?txid=${txid}", "POST")
       client.registerMethod("upload", config.torrentServer.url + "/addMetadata?token=${token}", "POST")
       client.registerMethod("seed", config.torrentServer.url + "/shareMetadata?token=${token}&torrentHash=${torrentHash}", "GET")
       client.registerMethod("download", config.torrentServer.url + "/getMetadata?token=${token}&torrentHash=${torrentHash}", "GET")
github Duke-Translational-Bioinformatics / duke-data-service / docker / builds / dredd / dredd_scripts / 05_projects_hooks.js View on Github external
hooks.before(DELETE_PROJECT, function (transaction,done) {
  var request = new Promise();
  var client = new Client();
  var request_payload = {
    "name": "Delete project for dredd - ".concat(shortid.generate()),
    "description": "A project to delete for dredd"
  };
  var args = {
    "headers": { "Content-Type": "application/json", "Authorization": process.env.MY_GENERATED_JWT },
    "data": request_payload
  };
  var request_path = hooks.configuration.server.concat('/projects');
  client.registerMethod("apiMethod", request_path, 'POST');
  client.methods.apiMethod(args, function(data, response) {
	// parsed response body as js object
  request.resolve(data);
  });
  request.then(function(data) {
    var url = transaction.fullPath;
github KyberNetwork / smart-contracts / priceChangerScript.js View on Github external
updatePrices( privateKey, sources, dests, rates, callback );
        });
        
    });
};

var printRates = function() {
    for( var i = 0 ; i < tokens.length ; i++ ){
        console.log(reserve.getPairInfo( tokens[i], ether )[0].toString(10) );
        console.log(reserve.getPairInfo( ether, tokens[i] )[0].toString(10)  );                
    } 
    
};

var Client = require('node-rest-client').Client; 
var client = new Client();
console.log("open");
/*
update(client,function(err,result){
    console.log(err,result);        
});*/
printRates();


setInterval(update,1000 * 60 * 5, client, function(err,result){
    console.log(err,result);
});


//for( var i = 0 ; i < 100 ; i++ ) update(null);
github klutchell / hue-bridge-backup / bridge.js View on Github external
Bridge.prototype.get = function(endpoint, fn) {
    
    var endpoint_url = "http://" + this.ip + "/api/" + this.user + "/" + endpoint;
    
    var client = new Client();
    
    console.log("GET " + endpoint_url);
    
	var req = client.get(endpoint_url, function (data, response) {
        fn(JSON.stringify(data, null, 2));
    });
     
    req.on('error', function (err) {
        console.log('request error', err);
    });
};
github IBM / real-time-payments / server.js View on Github external
function listDDAAccounts(id, fn) {
	var client = new Client(serviceBrokerRequestParameters);
	var args = {
		headers: GET_HEADERS
	};
	console.log("GET Accounts");
	var readDDAAccountsRequest = client.get(ddaBaseUrl + 'Accounts/?filter={"where":{"owner":"' + id + '"}}', args, function (data, response) {
		if( response.statusCode == 200 ) {
			return fn(null, data);
		} else {
			console.log(response.statusCode + ':' + response.statusMessage);
			return fn(response.statusMessage, null);
		}
	});
    readDDAAccountsRequest.on('error', function (err) {
		console.log('something went wrong on GET Accounts', err.request.options);
		console.log(err);
		return fn(err,null);

node-rest-client

node API REST client

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis

Popular node-rest-client functions