blob: 36f5d8bb349612539cd9ff47575e0824f6fbddfc [file] [view]
#Plugins
Build Status [![Build Status](https://travis-ci.org/apigee/microgateway-plugins.svg?branch=accumulate-request-fixes)](https://travis-ci.org/apigee/microgateway-plugins)
##Overview
This repo contains plugins for the [microgateway-core project](https://github.com/apigee/microgateway-core).
These plugins can be loaded into the microgateway calling the load plugin method
##Building a plugin
must contain an init method which returns an object literal with all of the handlers
```javascript
{
init:function(config,logger,stats){
return {
onrequest:function(req,res,[options],next){
},
...
}
}
}
```
init method must return an object with handler methods for each event
the available handlers are
* on_request
* ondata_request
* onend_request
* on_response
* ondata_response
* onend_response
* onclose_response
* onerror_response
the handler signature will look like
```javascript
function(sourceRequest,sourceResponse,[options],next){}
```
* sourceRequest: the request from the northbound server
* sourceResponse the response to the northbound server
* options: are the full scope of fields you might need to operate on.
```javascript
const options = {
targetResponse: options.targetResponse,
targetRequest: options.targetRequest,
sourceRequest: options.sourceRequest,
sourceResponse: options.sourceResponse,
data: data
};
```
* you must call next with an error if you errored out like
```javascript
next([err])
```