You are browsing documentation for an older version. See the latest documentation here.
PDK
The Plugin Development Kit (PDK) is set of Lua functions and variables that can be used by plugins to implement their own logic.
The PDK is originally released in Kong 0.14.0.
The PDK is guaranteed to be forward-compatible from its 1.0.0 release and onward.
The Plugin Development Kit is accessible from the kong
global variable,
and various functionalities are namespaced under this table, such as
kong.request
, kong.log
, etc.
kong.version
A human-readable string containing the version number of the currently running node.
Usage
print(kong.version) -- "2.0.0"
kong.version_num
An integral number representing the version number of the currently running node, useful for comparison and feature-existence checks.
Usage
if kong.version_num < 13000 then -- 000.130.00 -> 0.13.0
-- no support for Routes & Services
end
kong.configuration
A read-only table containing the configuration of the current Kong node, based on the configuration file and environment variables.
See kong.conf.default for details.
Comma-separated lists in the kong.conf
file get promoted to arrays of strings in this
table.
Usage
print(kong.configuration.prefix) -- "/usr/local/kong"
-- this table is read-only; the following throws an error:
kong.configuration.prefix = "foo"
kong.db
Instance of Kong’s DAO (the kong.db
module). Contains accessor objects
to various entities.
A more thorough documentation of this DAO and new schema definitions is to be made available in the future.
Usage
kong.db.services:insert()
kong.db.routes:select()
kong.dns
Instance of Kong’s DNS resolver, a client object from the lua-resty-dns-client module.
Note: Usage of this module is currently reserved to the core or to advanced users.
kong.worker_events
Instance of Kong’s IPC module for inter-workers communication from the lua-resty-events module.
Note: Usage of this module is currently reserved to the core or to advanced users.
kong.cluster_events
Instance of Kong’s cluster events module for inter-nodes communication.
Note: Usage of this module is currently reserved to the core or to advanced users.
kong.cache
Instance of Kong’s database caching object, from the kong.cache
module.
Note: Usage of this module is currently reserved to the core or to advanced users.