Module: restRequestSender

restRequestSender is an object that implements an abstraction level the actual REST request sending operation by exposing an object that implements an abstraction level the actual sending operation, allowing complex implementations to vary the behavior of all rest operations. It can be either called directly, as in Example-1-Direct, or it can be used to allow functions that wrap the rest operations, as in Example-2-Wrap or it can be replaced with a different object that implements those methods differently, for instance, additional calls (rest of otherwise) can be made before or after any rest calls, headers (such as security, checksum, token headers, etc.) can be added to all messages, etc.


Examples:

// call the first Get, then if successful, call the second
var eventChannel = require("./bootstrap/setupEventChannel")();
var restRequestSender = require("./infrastructure/restRequestSender");
restRequestSender.initialize({
  eventChannel: eventChannel
});
function callGetandGet(restOperation1,restOperation2)
{
    restRequestSender.sendGet(restOp).then(function(response1) {
        this.logger.info("[response1] " + JSON.stringify(response1));
           // send second get only if first successful
          restRequestSender.sendGet(restOp).then(function(response2) {
             this.logger.info("[response2] " + JSON.stringify(response2))
          }
    }, function(error1) {
        this.logger.warning("[Error1] " + error1);
    });
}
var eventChannel = require("./bootstrap/setupEventChannel")();
var restRequestSender = require("./infrastructure/restRequestSender");
restRequestSender.initialize({
  eventChannel: eventChannel
});
var sendGet = function (fullUrl) {
    var restOp = this.restOperationFactory.createRestOperationInstance()
        .setUri(this.restHelper.makeRestnodedUri(fullUrl))
        .setContentType("text/plain")
        .setIsSetBasicAuthHeader(true);
    return this.restRequestSender.sendGet(restOp);
};

restRequestSender Methods

(static) -> sendGet(restOp)

Sets the request method to GET and sends out the operation. Return result is the promise which will resolved in future

Parameters:
Name Required Type Default Value Description
restOp Y setupRestOperationFactory.RestOperation   the rest operation to be acted on (the content thereof will be sent)

Returns:
Type Description
Promise The [promise](https://www.npmjs.com/package/q) object that represents the return value or the thrown exception that may eventually be provided.

(static) -> sendPost(restOp)

Sets the request method to POST and sends out the operation. Return result is the promise which will resolved in future. Body is mandated on POST request.

Parameters:
Name Required Type Default Value Description
restOp Y setupRestOperationFactory.RestOperation   restOp the rest operation to be acted on (the content thereof will be sent)

Returns:
Type Description
Promise The [promise](https://www.npmjs.com/package/q) object that represents the return value or the thrown exception that may eventually be provided.

(static) -> sendPatch(restOp)

Sets the request method to PATCH and sends out the operation. Return result is the promise which will resolved in future. Body is mandated on PATCH request.

Parameters:
Name Required Type Default Value Description
restOp Y setupRestOperationFactory.RestOperation   restOp the rest operation to be acted on (the content thereof will be sent)

Returns:
Type Description
Promise The [promise](https://www.npmjs.com/package/q) object that represents the return value or the thrown exception that may eventually be provided.

Examples:

// issue a patch and log success or failure based on the returned promise
this.restRequestSender.sendPatch(restOp).then(function(response) {
     this.logger.info("[Patch success] " + JSON.stringify(response));
}, function(error) {
    this.logger.warning("[Patch failure] " + error);
});

(static) -> sendPut(restOp)

Sets the request method to PUT and sends out the operation. Return result is the promise which will resolved in future. Body is mandated on PUT request.

Parameters:
Name Required Type Default Value Description
restOp Y setupRestOperationFactory.RestOperation   restOp the rest operation to be acted on (the content thereof will be sent)

Returns:
Type Description
Promise The [promise](https://www.npmjs.com/package/q) object that represents the return value or the thrown exception that may eventually be provided.

(static) -> sendDelete(restOp)

Sets the request method to DELETE and sends out the operation. Return result is the promise which will resolved in future.

Parameters:
Name Required Type Default Value Description
restOp Y setupRestOperationFactory.RestOperation   restOp the rest operation to be acted on (the content thereof will be sent)

Returns:
Type Description
Promise The [promise](https://www.npmjs.com/package/q) object that represents the return value or the thrown exception that may eventually be provided.

(static) -> send(restOp)

Sends out the requested operation. Return result is the promise which will resolved in future

Parameters:
Name Required Type Default Value Description
restOp Y setupRestOperationFactory.RestOperation   restOp the rest operation to be acted on (the content thereof will be sent)

Returns:
Type Description
Promise The [promise](https://www.npmjs.com/package/q) object that represents the return value or the thrown exception that may eventually be provided.