---
title: "Datakit"
description: "Some examples on how to use the powerful transformation and integration engine"
url: "https://dev-portal.dehaven.org/datakit"
image: "https://dev-portal.dehaven.org/_og/d/c_Ocean.takumi,title_Datakit,description_Some+examples+on+how+to+use+the+powerful+transformation+and+integration+engine,props_eyJ0aGVtZSI6eyJtb2RlIjoibGlnaHQiLCJjb2xvcnMiOnsicHJpbWFyeSI6IiMyRUE4QTYifX19,p_Ii9kYXRha2l0Ig,s_9mj4X2l-pUJTkkHT.png"
---

# Datakit

Datakit provides a powerful transformation and integration engine

## [Table of contents](#table-of-contents)

The demo examples for Datakit are all based on the examples provided in the plugin documentation at [https://developer.konghq.com/plugins/datakit/](https://developer.konghq.com/plugins/datakit/)

# Demo scenes

The following examples have been added to the demo system to show different typical use cases which can be solved using Datakit.

## [Cat and dog](#cat-and-dog)

Will call out two to different APIs providing facts about cats and dogs and will responed with a combined payload with data from both cats and dogs

Based on

-   [https://catfact.ninja/fact](https://catfact.ninja/fact) and
-   [https://dogapi.dog/api/v1/facts](https://dogapi.dog/api/v1/facts)

### [Sequence](#sequence)

```mermaid
sequenceDiagram
Client ->> Kong Gateway: /datakit/cat-and-dog
Kong Gateway ->> Cats endpoint: GET https://catfact.ninja/fact
Cats endpoint ->> Kong Gateway: A random fact about cats
Kong Gateway ->> Dogs endpoint: GET https://dogapi.dog/api/v1/facts
Dogs endpoint ->> Kong Gateway: A random fact about dogs
Kong Gateway ->> Client: A combined response with both facts
```

### [Example response](#example-response)

```json
{
    "cat_fact": "Tabby cats are thought to get their name from Attab, a district in Baghdad, now the capital of Iraq.",
    "dog_fact": "All dogs can be traced back 40 million years ago to a weasel-like animal called the Miacis which dwelled in trees and dens. The Miacis later evolved into the Tomarctus, a direct forbear of the genus Canis, which includes the wolf and jackal as well as the dog."
}
```

## [Header manipulation](#header-manipulation)

Injects two headers into the request:

-   X-Datakit-Added-Header-1 and
-   X-Datakit-Added-Header-2

Also modifies incoming headers from your request and adds the prefix `X-Request-` to them. So for example your header `foo` will become `X-Request-Foo`

### [Sequence](#sequence-1)

```mermaid
sequenceDiagram
Client ->> Kong Gateway: /datakit/header-manipulation with header foo:bar
Kong Gateway ->> Echo Service: Inject and modify headers
Echo Service ->> Kong Gateway: The echo response
Kong Gateway ->> Client: The echo response
```

### [Example response](#example-response-1)

```json
{
  (...)
  "headers": {
    "X-Datakit-Added-Header-1": "This is an auto-added header",
    "X-Datakit-Added-Header-2": "This is another auto-added header",
    "X-Request-Foo": "bar"
  }
}
```

## [External authenticatipn](#external-authenticatipn)

Before reaching the services endpoint will reach out to a token endpoint and inject it's response into the request

For this example we are using the UUID endpoint of httpbin as example for the external auth, but in the code you can see we could inject an api key and use client credentials flow

### [Sequence](#sequence-2)

```mermaid
sequenceDiagram
Client ->> Kong Gateway: /datakit/external-auth with header apikey:foo
Kong Gateway ->> Token Endpoint: we are using UUID endpoint as example
Token Endpoint ->> Kong Gateway: Returns token (uuid)
Kong Gateway ->> Echo Service: Inject token into request
Echo Service ->> Kong Gateway: The echo response incl. token
Kong Gateway ->> Client: The echo response incl. token
```

### [Example response](#example-response-2)

```json
{
  (...)
  "headers": {
     "Authorization": "Bearer 84d52319-f375-4be4-9524-e999c503a5d1"
  }
}
```