Get started with Datakit

Uses: Kong Gateway decK
Incompatible with
konnect
Related Resources
Minimum Version
Kong Gateway - 3.11
TL;DR

Datakit is a Kong Gateway plugin that allows you to interact with third-party APIs. In this guide, learn how to configure the plugin to combine responses from two third-party API calls and return directly to the client.

Prerequisites

This tutorial requires Kong Gateway Enterprise. If you don’t have Kong Gateway set up yet, you can use the quickstart script with an enterprise license to get an instance of Kong Gateway running almost instantly.

  1. Export your license to an environment variable:

     export KONG_LICENSE_DATA='LICENSE-CONTENTS-GO-HERE'
    
    Copied to clipboard!
  2. Run the quickstart script:

    curl -Ls https://get.konghq.com/quickstart | bash -s -- -e KONG_LICENSE_DATA 
    
    Copied to clipboard!

    Once Kong Gateway is ready, you will see the following message:

     Kong Gateway Ready
    

Enable Datakit

Test out Datakit by combining responses from two third-party API calls, then returning the result directly back to the client:

echo '
_format_version: "3.0"
plugins:
  - name: datakit
    service: example-service
    config:
      nodes:
      - name: CAT_FACT
        type: call
        url: https://catfact.ninja/fact
      - name: DOG_FACT
        type: call
        url: https://dogapi.dog/api/v1/facts
      - name: JOIN
        type: jq
        inputs:
          cat: CAT_FACT.body
          dog: DOG_FACT.body
        jq: |
          {
            cat_fact: .cat.fact,
            dog_fact: .dog.facts[0],
          }
      - name: EXIT
        type: exit
        inputs:
          body: JOIN
        status: 200
' | deck gateway apply -
Copied to clipboard!

Validate

Access the Service using the /anything path:

 curl -i -X GET "http://localhost:8000/anything"
Copied to clipboard!

You should get a 200 response with a random fact from each fact generator called in the config:

{
    "cat_fact": "The longest living cat on record according to the Guinness Book belongs to the late Creme Puff of Austin, Texas who lived to the ripe old age of 38 years and 3 days!",
    "dog_fact": "Greyhounds can reach a speed of up to 45 miles per hour."
}

Cleanup

curl -Ls https://get.konghq.com/quickstart | bash -s -- -d
Copied to clipboard!

Did this doc help?

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!