1 | # Plugins
|
2 |
|
3 | Build Status [![Build Status](https://travis-ci.org/apigee/microgateway-plugins.svg?branch=accumulate-request-fixes)](https://travis-ci.org/apigee/microgateway-plugins)
|
4 |
|
5 | ## Overview
|
6 | This repo contains plugins for the [microgateway-core project](https://github.com/apigee/microgateway-core).
|
7 |
|
8 | These plugins can be loaded into the microgateway calling the load plugin method
|
9 |
|
10 | ## Building a plugin
|
11 | must contain an init method which returns an object literal with all of the handlers
|
12 |
|
13 | ```javascript
|
14 | {
|
15 | init:function(config,logger,stats){
|
16 | return {
|
17 | onrequest:function(req,res,[options],next){
|
18 | },
|
19 | ...
|
20 | }
|
21 | }
|
22 | }
|
23 | ```
|
24 |
|
25 | init method must return an object with handler methods for each event
|
26 |
|
27 | the available handlers are
|
28 |
|
29 | * on_request
|
30 | * ondata_request
|
31 | * onend_request
|
32 | * on_response
|
33 | * ondata_response
|
34 | * onend_response
|
35 | * onclose_response
|
36 | * onerror_response
|
37 |
|
38 | The handler signature will look like :
|
39 |
|
40 | ```javascript
|
41 | function(sourceRequest,sourceResponse,[options],next){}
|
42 | ```
|
43 |
|
44 | * sourceRequest: the request from the northbound server;
|
45 | * sourceResponse the response to the northbound server;
|
46 | * options: are the full scope of fields you might need to operate on.
|
47 |
|
48 | ```javascript
|
49 | const options = {
|
50 | targetResponse: options.targetResponse,
|
51 | targetRequest: options.targetRequest,
|
52 | sourceRequest: options.sourceRequest,
|
53 | sourceResponse: options.sourceResponse,
|
54 | data: data
|
55 | };
|
56 | ```
|
57 | * you must call next with an error if you errored out like
|
58 |
|
59 | ```javascript
|
60 | next([err])
|
61 | ```
|