Get started with Datakit
Datakit is a Kong Gateway plugin that allows you to interact with third-party APIs.
To enable it, start Kong Gateway with wasm = on
.
Then, you can configure the plugin to combine responses from two third-party API calls and return directly to the client.
Prerequisites
decK
decK is a CLI tool for managing Kong Gateway declaratively with state files. To complete this tutorial you will first need to install decK.
Kong Gateway license
This tutorial requires a Kong Gateway license. Export your license to an environment variable:
export KONG_LICENSE_DATA='LICENSE_CONTENTS_GO_HERE'
Start Kong Gateway with the WASM engine
Start the Kong Gateway container with the KONG_WASM
variable:
curl -Ls https://get.konghq.com/quickstart | bash -s -- \
-e KONG_LICENSE_DATA \
-e KONG_WASM=on
Create a Service and a Route
To be able to validate the configuration, we need to create a Gateway Service and a Route:
echo '
_format_version: "3.0"
services:
- name: example-service
url: http://httpbin.konghq.com
routes:
- name: example-route
paths:
- "/"
strip_path: true
service:
name: example-service
' | deck gateway apply -
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:
debug: true
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
Destroy the Kong Gateway container
curl -Ls https://get.konghq.com/quickstart | bash -s -- -d