vanquish vanquish - 1 year ago 185
Javascript Question

Javascript - How to make REST API Calls

I am trying to access Firebase Database using REST API. Using cURL i am able to retrive data. I am unable to do the same in javascript.


curl ''


var request = require('request');

var options = {
url: '' };

function callback(error, response, body) {
if (!error && response.statusCode == 200) {
} }

request(options, callback);

Note: The above code i am trying to run on Bluemix/OpenWhisk.
Kindly let me know how to fix this.

Answer Source

The structure of your action is a bit off for OpenWhisk. Javascript actions need to have a main method and you'll have to use whisk.async() and whisk.done() to make your (asynchronous) REST API call work as you'd expect it.

An example of how to call an external API using a Javascript action in OpenWhisk can be found here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download