Developer Guide
Overview#
This documentation explains how to develop this project.
Prerequisites#
- Python 3.6+
- APISIX 2.7.0
Debug#
- Run
make setupInstallation dependencies - Run
make devto start it
Plugin#
Plugin directory#
/path/to/apisix-python-plugin-runner/apisix/pluginthe .py files in this directory autoload
Plugin example#
/path/to/apisix-python-plugin-runner/apisix/plugin/say.pyPlugin Format#
from apisix.runner.plugin.base import Basefrom apisix.runner.http.request import Requestfrom apisix.runner.http.response import Response
class Test(Base): def __init__(self): super(Test, self).__init__(self.__class__.__name__)
def filter(self, request: Request, response: Response): """ The plugin executes the main function :param request: request parameters and information :param response: response parameters and information :return: """ # Get plugin configuration information through `self.config` # print(self.config)
# Set response headers headers = request.headers headers["X-Resp-A6-Runner"] = "Python" response.headers = headers
# Set response body response.body = "Hello, Python Runner of APISIX"
# Set response status code response.status_code = 201
# Set the plug-in to `stop` type, default `rewrite`, use `self.rewrite()` to declare it as `rewrite` type. self.stop()- The plugin must inherit the
Baseclass - The plugin must implement the
filterfunction filterfunction parameters can only containRequestandResponseclasses as parameters- Request parameter can get request information
- Response parameter can set response information
self.configcan get plug-in configuration information- Use
self.stop()to set the plugin as astoptype plugin, which will interrupt the request. - Use
self.rewrite()to set the plugin as arewritetype plugin, which will not interrupt the request.
Test#
Run make test.
Data Format#
Data Protocol#
1 byte of type + 3 bytes of length + data