diff --git a/README.md b/README.md index d68789c4..c006b7d8 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,15 @@ security, traffic control, serverless, analytics & monitoring, transformations, It also provides highly extensible API, allowing common phases to be mounted, and users can use these api to develop their own plugins. -APISIX supports writing plugins in multiple languages in version [2.7.0](https://github.com/apache/apisix/blob/master/CHANGELOG.md#270), this project is APISIX Java side implementation that supports writing plugins in java. +Version Matrix +------------- + +| apisix-java-plugin-runner | APISIX | +|---------------------------|-----------------------------------------------------------------------------| +| 0.1.0 | >= [2.7.0](https://github.com/apache/apisix/blob/master/CHANGELOG.md#270) | +| 0.2.0 | >= [2.10.2](https://github.com/apache/apisix/blob/master/CHANGELOG.md#2102) | How it Works ------------- diff --git a/docs/en/latest/development.md b/docs/en/latest/development.md index 1eeaa1a4..db007a76 100644 --- a/docs/en/latest/development.md +++ b/docs/en/latest/development.md @@ -87,6 +87,74 @@ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f13 apisix-java-plugin-runner will look for implementation classes named `FooFilter`, and the name of each filter's implementation class is the return value of its overridden function `public String name()`. +#### The functions must be implemented of filter execution + +- `String name();` + + description: return the name of plugin filter + + code example: + + ```java + @Override + public String name() { + return "FooFilter"; + } + ``` + +- `void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain);` + + description: implementing custom business logic + + code example: + + ```java + @Override + public void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain) { + // get conf of current filter + String configStr = request.getConfig(this); + Gson gson = new Gson(); + Map conf = new HashMap<>(); + // convert according to the actual configured conf type + conf = gson.fromJson(configStr, conf.getClass()); + + // get extra info + String remoteAddr = request.getVars("remote_addr"); + String serverPort = request.getVars("server_port"); + String body = request.getBody(); + + chain.filter(request, response); + } + ``` + +- `List requiredVars();` + + description: declare in advance the nginx variables you want to use in the current filter + + code example: + + ```java + @Override + public List requiredVars() { + List vars = new ArrayList<>(); + vars.add("remote_addr"); + vars.add("server_port"); + return vars; + } + ``` + +- `Boolean requiredBody();` + + description: whether the request body is required in the current filter, true means yes. + + code example: + + ```java + @Override + public Boolean requiredBody() { + return true; + } + ``` #### Rewrite Request diff --git a/docs/zh/Quick Start.md b/docs/zh/quick-start.md similarity index 100% rename from docs/zh/Quick Start.md rename to docs/zh/quick-start.md