Http Calls

Prev Next

Http Calls

Http calls are performed with the help of classes provided by Data Flow.

Example

A sample call to accuweather that gets the air temperature of İstanbul and uses this information to send an event would be as follows:

var request = new SimpleHttpRequest();	
request.url = "https://dataservice.accuweather.com/currentconditions/v1/318251?apikey=write_your_apikey_here";
var credentialId = "";	
 new HttpAgent().call(
     request, 
     credentialId,
     function(response){
		if (200 != response.httpStatusCode)
		{
            return;
        }
        nodeBase.log(LogLevel.info, "weather response : " + JSON.stringify(response));
        var weatherJson = JSON.parse(response.body);
        var degrees = weatherJson[0].Temperature.Metric.Value;
        nodeBase.log(LogLevel.info, degrees + " C degrees");

        var outData = { "degrees": degrees, "city": cityName };
        var eventInformation = new EventInformation(
            channelIndex, 
            "accuweather", 
            "weather", 
            outData,
            eventInformation.StartSampleIndex, 
            eventInformation.EndSampleIndex
        )
        raiseEvent(eventInformation);
     }
);

SimpleHttpRequest

SimpleHttpRequest is the http request object we use with HttpAgent.

Properties

name default definition
type HttpRequestType.get HttpRequestType.get or HttpRequestType.post
url empty url as a string
headers an empty Object a string dictionary
body empty body content as a string
ignoreSslErrors false When set to true any https certificate errors will be ignored

HttpAgent

HttpAgent is the class provided by Data Flow for custom nodes' http client needs.

call

HttpAgent has the method call that performs an async http request.

call(simpleHttpRequest, credentialId, responseListener)

Parameters:

name explanation
simpleHttpRequest the request object.
credentialId Id of a credential that will be used in this request. May be empty for requests that does not require authentication. The Data Flow credentials are managed in Credential page
responseListener A function object that will be called when the http request has completed. function(response){} It has a response object of type SimpleHttpResponse as its only parameter.

SimpleHttpResponse

SimpleHttpResponse is the http response object we use with HttpAgent.

Properties

name definition
headers response headers
body response body
networkErrorCode 0 for success. Error code from the underlying operating system or network stack.
httpStatusCode Http status code for this response.
httpStatusText Textual explanation for http errors