Most of the time, it makes sense for your plugin to be configurable to answer all of your users’ needs. Your plugin’s configuration is stored in the data store for Kong Gateway to retrieve it and pass it to your handler.lua methods when the plugin is being executed.
The configuration consists of a Lua table, in what we call a schema. It contains key/value properties that the user will set when enabling the plugin. Kong Gateway provides you with a way of validating the user’s configuration for your plugin.
Your plugin’s configuration is verified against your schema when a user enables or updates a plugin.
For example, when a user performs the following request:
curl -X POST http://localhost:8001/services/{service-name-or-id}/plugins \
-d "name=my-custom-plugin" \
-d "config.foo=bar"
If all properties of the config
object are valid according to your schema,
then the API would return 201 Created
and the plugin would be stored in the
database along with its configuration:
{
foo = "bar"
}
If the configuration is not valid, the Admin API would return 400 Bad Request
and the appropriate error messages.