
The curl POST command can be used to configure a plugin for a service. This assumes you have already created a service. If not, refer to Kong - create service using cURL. Let's say you've created a service named "foo-service".
On the Kong server
If Kong is running on docker, refer to Kong - Docker container command line for the steps on how to issue commands in the Kong Docker container. Assuming you are using the default kong.conf file, the Kong Admin API will listen on port 8001.
If issuing this command on the Kong server, this command will configure the key-auth plugin for foo-service.
curl -X POST "http://localhost:8001/services/foo-service/plugins" --data "name=key-auth"
From a remote server
If issuing this command from a remote server, this command will configure the key-auth plugin for foo-service.
curl -X POST "http://hostname:8000/admin-api/services/foo-service/plugins" --data "name=key-auth"
Validation
If the plugin was successfully configured, something like this should be displayed. Additionally, the cURL command can be used to ensure the plugin exists.
{
"created_at":1584418734,
"config":{"key_names":["apikey"],
"run_on_preflight":true,
"anonymous":null,
"hide_credentials":false,
"key_in_body":false},
"id":"75212b3c-2bdc-48b8-b39e-d94b46501a81",
"service":{"id":"fbb57bfd-124b-451c-841c-dbfea2b9ee8b"},
"enabled":true,
"protocols":["grpc","grpcs","http","https"],
"name":"key-auth",
"consumer":null,
"route":null,
"tags":null
}
Did you find this article helpful?
If so, consider buying me a coffee over at