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'
    
  2. Run the quickstart script:

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

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

     Kong Gateway Ready
    

decK is a CLI tool for managing Kong Gateway declaratively with state files. To complete this tutorial you will first need to install decK.

For this tutorial, you’ll need Kong Gateway entities, like Gateway Services and Routes, pre-configured. These entities are essential for Kong Gateway to function but installing them isn’t the focus of this guide. Follow these steps to pre-configure them:

  1. Run the following command:

    echo '
    _format_version: "3.0"
    services:
      - name: example-service
        url: http://httpbin.konghq.com/anything
    routes:
      - name: example-route
        paths:
        - "/anything"
        service:
          name: example-service
    ' | deck gateway apply -
    

To learn more about entities, you can read our entities documentation.

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 -

Validate

Access the Service using the /anything path:

 curl -i -X GET "http://localhost:8000/anything"

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
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!