public-api
With the public-api
plugin, we put all public APIs into the general HTTP API router, which is consistent with the normal Route registered by the user and can apply any plugin. The public API added in the user plugin is no longer expose by default by APISIX, and the user has to manually configure the Route for it, the user can configure any uri and plugin.
We take the jwt-auth
token sign API as an example to show how to configure the plugin. Also, the key-auth
will be used to show how to configure the protection plugin for the public API.
The use of key-auth and jwt-auth requires the configuration of a consumer that contains the configuration of these plugins, and you need to create one in advance, the process will be omitted here.
Let’s test it.
$ curl 'http://127.0.0.1:9080/apisix/plugin/jwt/sign?key=user-key'
It will respond to a text JWT.
Let’s setup another route.
$ curl 'http://127.0.0.1:9080/gen_token?key=user-key'
It will still respond to a text JWT. We can see that users are free to configure URI for the public API to match.
Let’s modify the last route and add key-auth
authentication to it.
Let’s test it.
$ curl -i 'http://127.0.0.1:9080/gen_token?key=user-key'
# Failed request
$ curl -i 'http://127.0.0.1:9080/gen_token?key=user-key'