Adding Consumers

In the last section, we learned how to add plugins to Kong, in this section we’re going to learn how to add consumers to your Kong instances. Consumers are associated to individuals using your Service, and can be used for tracking, access management, and more.

Before you start

1. Create a Consumer through the RESTful API

Lets create a user named Jason by issuing the following request:

  1. curl -i -X POST \
  2. --url http://localhost:8001/consumers/ \
  3. --data "username=Jason"

You should see a response similar to the one below:

  1. HTTP/1.1 201 Created
  2. Content-Type: application/json
  3. Connection: keep-alive
  4. {
  5. "username": "Jason",
  6. "created_at": 1428555626000,
  7. "id": "bbdf1c48-19dc-4ab7-cae0-ff4f59d87dc9"
  8. }

Congratulations! You’ve just added your first consumer to Kong.

Note: Kong also accepts a custom_id parameter when creating consumers to associate a consumer with your existing user database.

2. Provision key credentials for your Consumer

Now, we can create a key for our recently created consumer Jason by issuing the following request:

  1. curl -i -X POST \
  2. --url http://localhost:8001/consumers/Jason/key-auth/ \
  3. --data 'key=ENTER_KEY_HERE'

3. Verify that your Consumer credentials are valid

We can now issue the following request to verify that the credentials of our Jason Consumer is valid:

  1. curl -i -X GET \
  2. --url http://localhost:8000 \
  3. --header "Host: example.com" \
  4. --header "apikey: ENTER_KEY_HERE"

Next Steps

Now that we’ve covered the basics of adding Services, Routes, Consumers and enabling Plugins, feel free to read more on Kong in one of the following documents:

Questions? Issues? Contact us on one of the Community Channels for help!