Plugin Development - Introduction
What are plugins and how do they integrate with Kong?
Before going further, it is necessary to briefly explain how Kong is built, especially how it integrates with Nginx and what Lua has to do with it.
lua-nginx-module enables Lua scripting capabilities in Nginx. Instead of compiling Nginx with this module, Kong is distributed along with OpenResty, which already includes lua-nginx-module. OpenResty is not a fork of Nginx, but a bundle of modules extending its capabilities.
Hence, Kong is a Lua application designed to load and execute Lua modules (which we more commonly refer to as “plugins”) and provides an entire development environment for them, including database abstraction, migrations, helpers and more…
Your plugin will consist of Lua modules which will be loaded and executed by Kong, and it will benefit from two APIs:
- lua-nginx-module API: allows interaction with Nginx itself, such as, for example, retrieving the request/response, or accessing Nginx’s shared memory zone.
- Kong’s plugin environment: allows interaction with the datastore holding your configurations (APIs, Consumers, Plugins…) and various helpers allowing the interaction of plugins between each other. This is the environment that will be described by this guide.
This guide assumes that you are familiar with Lua
and the lua-nginx-module API
and will only describe Kong's plugin environment.
Next: File structure of a plugin ›