Skip to content

Commit 898ada4

Browse files
authored
docs: update developer-guide and getting-started document to 0.2.0 (#44)
1 parent 1498038 commit 898ada4

File tree

2 files changed

+43
-30
lines changed

2 files changed

+43
-30
lines changed

docs/en/latest/developer-guide.md

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This documentation explains how to develop this project.
2828
## Prerequisites
2929

3030
* Python 3.7+
31-
* APISIX 2.7.0
31+
* APISIX 2.7.0+
3232

3333
## Debug
3434

@@ -56,56 +56,69 @@ the `.py` files in this directory autoload
5656
#### Plugin Format
5757

5858
```python
59-
from apisix.runner.plugin.base import Base
59+
from typing import Any
6060
from apisix.runner.http.request import Request
6161
from apisix.runner.http.response import Response
62+
from apisix.runner.plugin.core import PluginBase
6263

6364

64-
class Test(Base):
65-
def __init__(self):
66-
super(Test, self).__init__(self.__class__.__name__)
65+
class Test(PluginBase):
6766

68-
def filter(self, request: Request, response: Response):
67+
def name(self) -> str:
68+
"""
69+
The name of the plugin registered in the runner
70+
:return:
71+
"""
72+
return "test"
73+
74+
def config(self, conf: Any) -> Any:
75+
"""
76+
Parse plugin configuration
77+
:param conf:
78+
:return:
79+
"""
80+
return conf
81+
82+
def filter(self, conf: Any, request: Request, response: Response):
6983
"""
7084
The plugin executes the main function
85+
:param conf:
86+
plugin configuration after parsing
7187
:param request:
7288
request parameters and information
7389
:param response:
7490
response parameters and information
7591
:return:
7692
"""
77-
# Get plugin configuration information through `self.config`
78-
# print(self.config)
79-
80-
# Setting the request object will continue to forward the request
81-
82-
# Rewrite request headers
83-
request.headers["X-Resp-A6-Runner"] = "Python"
8493

85-
# Rewrite request args
86-
request.args["a6_runner"] = "Python"
94+
# print plugin configuration
95+
print(conf)
8796

88-
# Rewrite request path
89-
request.path = "/a6/python/runner"
97+
# Fetch request nginx variable `host`
98+
host = request.get_var("host")
99+
print(host)
90100

91-
# Setting the response object will terminate the request and respond to the data
101+
# Fetch request body
102+
body = request.get_body()
103+
print(body)
92104

93105
# Set response headers
94-
response.headers["X-Resp-A6-Runner"] = "Python"
106+
response.set_header("X-Resp-A6-Runner", "Python")
95107

96108
# Set response body
97-
response.body = "Hello, Python Runner of APISIX"
109+
response.set_body("Hello, Python Runner of APISIX")
98110

99111
# Set response status code
100-
response.status_code = 201
112+
response.set_status_code(201)
101113
```
102114

103-
- The plugin must inherit the `Base` class
104-
- The plugin must implement the `filter` function
105-
- `filter` function parameters can only contain `Request` and `Response` classes as parameters
106-
- Request parameter can get and set request information
107-
- Response parameter can set response information
108-
- `self.config` can get plug-in configuration information
115+
- Plugins must inherit the `PluginBase` class and implement all functions.
116+
- `name` function: used to set the registered plugin name.
117+
- `config` function: used to parse plugin configuration.
118+
- `filter` function: used to filter requests.
119+
- `conf` parameter: plugin configuration after parsing.
120+
- `request` parameter: Request object, which can be used to get and set request information.
121+
- `response` parameter: Response object, which can be used to set response information.
109122

110123
## Test
111124

docs/en/latest/getting-started.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This document explains how to use Python Runner
2727
## Prerequisites
2828

2929
* Python 3.7+
30-
* APISIX 2.7.0
30+
* APISIX 2.7.0+
3131

3232

3333
## Installation
@@ -48,7 +48,7 @@ $ make install
4848
#### Run APISIX Python Runner
4949
```bash
5050
$ cd /path/to/apisix-python-plugin-runner
51-
$ APISIX_LISTEN_ADDRESS=unix:/tmp/runner.sock python3 bin/py-runner start
51+
$ make dev
5252
```
5353

5454
#### Modify APISIX configuration file
@@ -74,7 +74,7 @@ apisix:
7474
key: edd1c9f034335f136f87ad84b625c8f1
7575
role: admin
7676
ext-plugin:
77-
cmd: [ "python3", "/path/to/apisix-python-plugin-runner/apisix/main.py", "start" ]
77+
cmd: [ "python3", "/path/to/apisix-python-plugin-runner/bin/py-runner", "start" ]
7878
```
7979

8080
### Log level and socket configuration (Optional)

0 commit comments

Comments
 (0)