Integration Agent-compatible XMIO class for Integration Builder

Not Yet Reviewed

Context

The Integration Builder has several helper functions LINKHERE, but there is still a bit of overhead. So I've come up with this _XMIO function that mimics the XMIO function in the IA.

Usage

var XMIO = new _XMIO( "Endpoint Name Here" );
var resp = XMIO.get( "/path/to/my/resource" );

or for POST

var payload = {
"item": "value",
"array": [ "stuff", "value", "other stuff" ]
}

var headers = {
"Content-Type": "application/json",
"X-Some-other-header": "value here"
}

var XMIO = new _XMIO( "Endpoint Name Here" );
var resp = XMIO.post( JSON.stringify( payload ), "/other/path/here", headers );

Code

function _XMIO( endpoint ) {
this.endpoint = endpoint;
this.post = function( jsonStr, path, headers ) {
return this.execute('POST', jsonStr, path, headers );
};
this.put = function( jsonStr, path, headers ) {
return this.execute('PUT', jsonStr, path, headers );
};
this.get = function( path, headers ) {
return this.execute('GET', null, path, headers );
};
this.execute = function ( method, jsonStr, path, headers ) {

var request = {
'endpoint': this.endpoint,
'method': method,
'path': path
}

if ( headers === undefined ) {
if ( method !== 'GET') {
request.headers = {'Content-Type' : 'application/json'};
}
} else {
request.headers = headers;
}

var req = http.request( request );
var response = method !== 'GET' ? req.write( jsonStr ) : req.write();

return response;
};
}

 

0

Comments

0 comments

Please sign in to leave a comment.

Didn't find what you were looking for?

New post