Get started with Datakit
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
Kong Gateway running
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.
-
Export your license to an environment variable:
export KONG_LICENSE_DATA='LICENSE-CONTENTS-GO-HERE'
Copied! -
Run the quickstart script:
curl -Ls https://get.konghq.com/quickstart | bash -s -- -e KONG_LICENSE_DATA
Copied!Once Kong Gateway is ready, you will see the following message:
Kong Gateway Ready
decK v1.43+
decK is a CLI tool for managing Kong Gateway declaratively with state files. To complete this tutorial, install decK version 1.43 or later.
This guide uses deck gateway apply
, which directly applies entity configuration to your Gateway instance.
We recommend upgrading your decK installation to take advantage of this tool.
You can check your current decK version with deck version
.
Required entities
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:
-
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 -
Copied!
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: AUTHOR
type: call
url: https://httpbin.konghq.com/json
- name: UUID
type: call
url: https://httpbin.konghq.com/uuid
- name: JOIN
type: jq
inputs:
input1: AUTHOR.body
input2: UUID.body
jq: |
{
author: .input1.slideshow.author,
uuid: .input2.uuid,
}
- 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 UUID and a slideshow author:
{"uuid":"cfa1e3f8-6618-4d1f-89f0-da97490d7caa","author":"Yours Truly"}
Cleanup
Destroy the Kong Gateway container
curl -Ls https://get.konghq.com/quickstart | bash -s -- -d