accumulate - request response plugin in microgateway

Not applicable

Hi,

Has anyone implemented the accumulate request/response plugin in microgateway? If yes, can you please provide the steps to implement it. I referred to github but am not able to figure out how to implement it as the steps are not very clear. Can you please provide more details on the the above two plugins.

Thanks and Regards,

Shwetha

1 3 529
3 REPLIES 3

Hi Shwetha, you're talking about this plugin?

https://github.com/apigee/microgateway-plugins/blob/master/accumulate-request/index.js

To insert that into your own Micro-gateway configuration, you would follow the steps described here for "Developing a custom plugin":

http://docs.apigee.com/microgateway/latest/develop-custom-plugins

Maybe @Srinandan Sridhar has further suggestions.

Thanks @Dino. I have referred to the same documentation but I am not very clear on how it can be done.

@Srinandan Sridhar, can you please advise.

Regards,

Shwetha

Hello @Shwetha R Yermal,

The link from Dino above is great starting point and I pasted the direct link to the accumulate-request section below. However, you should read through the full page to obtain an understanding of how plugins work within the Microgateway.

http://docs.apigee.com/microgateway/latest/develop-custom-plugins#sampleplugins-accumulaterequest

You actually don't have to implement the accumulate-request or accumulate-response plugins because they are provided as default plugins when you install Microgateway. The list of the default plugins is available here. This means that you can include the plugin in the plugin sequence section of the Microgateway YAML configuration file as shown below.

edgemicro:
  ...
  plugins:
     dir: ../plugins
     sequence:   
     - oauth
     - accumulate-request
     - your-custom-plugin-to-manipulate-request

Once you include the accumulate request plugin, then you need to include your custom plugin after it to access the complete body of the response. Your custom plugin should implement the onend_request handler since that is where the full payload will be available.

//something like this...
module.exports.init = function(config, logger, stats) {


  return {
    onend_request: function(req, res, data, next) {
      //full payload available in data parameter
      next(null, data);
    }
  };
}

The accumulate-response plugin follows a similar approach except you need to provide your custom plugin before the accumulate-response plugin as shown below. This reason is explained in the plugin execution order documentation. In summary, the plugin execution order for the response path is from the bottom up. So the response path is:

1) accumulate-response

2) your-custom-plugin-to-manipulate-response

3) oauth

The accumulate-response plugin should be the last plugin in the plugin sequence.

edgemicro:
  ...
  plugins:
     dir: ../plugins
     sequence:   
     - oauth
     - your-custom-plugin-to-manipulate-response
     - accumulate-response

Your custom plugin should implement the onend_response handler since that is where the full payload will be available. (At least this is how it is supposed to work)

//something like this...
module.exports.init = function(config, logger, stats) {
  return {
    onend_response: function(req, res, data, next) {
      //full payload available in data parameter
      next(null, data);
    }
  };
}

When you include the plugins in the YAML file you can examine the start-up console log to confirm that the accumulate-response plugin was attached. You can see my console log below.

installed plugin from plugin2
installed plugin from accumulate-response