donglei / kong-middleman-plugin

A Kong plugin that enables you to make an extra HTTP POST request before calling an API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kong Middleman

A Kong plugin that enables an extra HTTP POST request before proxying the original.

Description

In some cases, you may need to validate a request to a separate server or service using custom logic before Kong proxies it to your API. Middleman enables you to do that by allowing you to make an extra HTTP request before calling an API endpoint.

Installation

Development

Navigate to kong/plugins folder and clone this repo

$ cd /path/to/kong/plugins
$ git clone https://github.com/pantsel/kong-middleman-plugin middleman
$ cd middleman
$ luarocks make *.rockspec

To make Kong aware that it has to look for the middleman plugin, you'll have to add it to the custom_plugins property in your configuration file.

custom_plugins:
    - middleman

Restart Kong and you're ready to go.

luarocks

$ luarocks install middleman

Configuration

You can add the plugin on top of an API by executing the following request on your Kong server:

$ curl -X POST http://kong:8001/apis/{api}/plugins \
    --data "name=middleman" \
    --data "config.url=http://myserver.io/validate"
    --data "config.response=table"
    --data "config.timeout=10000"
    --data "config.keepalive=60000"
form parameter default description
name The name of the plugin to use, in this case: middleman
config.url
required
The URL to which the plugin will make a JSON POST request before proxying the original request.
config.response
required
The type of response the middleman service is going to respond with
config.timeout Timeout (miliseconds) for the request to the URL specified above. Default value is 10000.
config.keepalive Keepalive time (miliseconds) for the request to the URL specified above. Default value is 60000.

Middleman will execute a JSON POST request to the specified url with the following body:

Attribute Description
body_data The body of the original request
url_args The url arguments of the original request
headers The headers of the original request

In the scope of your own endpoint, you may validate any of these attributes and accept or reject the request according to your needs. If an HTTP response code of 299 or less is returned, the request is accepted. Any response code above 299 will cause the request to be rejected.

Author

Panagis Tselentis

License

The MIT License (MIT)
=====================

Copyright (c) 2015 Panagis Tselentis

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

About

A Kong plugin that enables you to make an extra HTTP POST request before calling an API.

License:MIT License


Languages

Language:Lua 100.0%