Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions app/_kong_plugins/datakit/examples/convert-json-into-xml.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
description: |
Use the Datakit plugin to transform JSON request bodies into XML.

extended_description: |
Use the Datakit plugin to transform JSON request bodies into XML.

This example contains the following nodes:
1. The node `JSON_XML` converts the incoming JSON request body into XML format.
2. The node `EXIT` sends the produced XML data back directly as the response body, without proxying it upstream.

title: Transform JSON into XML
weight: 900


config:
debug: true
nodes:
- name: JSON_XML
type: json_to_xml
attributes_name_prefix: "-"
attributes_block_name: null
text_block_name: "#text"
input: request.body

- name: EXIT
type: exit
inputs:
body: JSON_XML

tools:
- deck
- admin-api
- konnect-api
- kic
- terraform

min_version:
gateway: '3.13'
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
description: |
Use the Datakit plugin to transform JSON request bodies into XML before sending them to an external service, then convert the XML response back into JSON.

extended_description: |
Use the Datakit plugin to transform JSON request bodies into XML before sending them to an external service, then convert the XML response back into JSON.

This example contains the following nodes:
1. The node `JSON_XML` converts the incoming JSON request body into XML format.
2. The node `CALL` sends the XML data to an external SOAP API.
3. The node `XML_JSON` converts the XML response from the external SOAP API back into JSON format and sets it as the response body.

title: Transform JSON into XML and back
weight: 900


config:
debug: true
nodes:
- name: JSON_XML
type: json_to_xml
attributes_block_name: "#attr"
input: request.body

- name: CALL
type: call
url: http://localhost:7180
method: POST
inputs:
body: JSON_XML

- name: XML_JSON
type: xml_to_json
input: CALL.body
attributes_block_name: "#attr"
output: response.body

tools:
- deck
- admin-api
- konnect-api
- kic
- terraform

min_version:
gateway: '3.13'
38 changes: 38 additions & 0 deletions app/_kong_plugins/datakit/examples/convert-xml-into-json.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
description: |
Use the Datakit plugin to transform XML request bodies into JSON.

extended_description: |
Use the Datakit plugin to transform XML request bodies into JSON.

This example contains the following nodes:
1. The node `XML_JSON` converts the incoming XML request body into JSON format.
2. The node `EXIT` sends the produced JSON data back directly as the response body, without proxying it upstream.

title: Transform XML into JSON
weight: 900

config:
debug: true
nodes:
- name: XML_JSON
type: xml_to_json
attributes_block_name: null
attributes_name_prefix: "-"
recognize_type: true
text_block_name: "#text"
input: request.body
xpath: null
- name: EXIT
type: exit
inputs:
body: XML_JSON

tools:
- deck
- admin-api
- konnect-api
- kic
- terraform

min_version:
gateway: '3.13'
138 changes: 138 additions & 0 deletions app/_kong_plugins/datakit/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ rows:
description: Authenticate to a third-party service using Vault secrets.
- usecase: "[Conditionally fetch or store cache data](/plugins/datakit/examples/conditionally-store-cached-items/)"
description: "Leverage the `cache` and `branch` nodes to conditionally store or retrieve cache items."
- usecase: "[Transform XML into JSON, or JSON into XML](/plugins/datakit/examples/convert-json-to-xml-and-back/)"
description: "Transform JSON requests into XML so you can send the data to a SOAP service, then transform the resulting XML back into JSON."
{% endtable %}
<!--vale on-->

Expand Down Expand Up @@ -1493,6 +1495,142 @@ Set common request headers for different API requests:
headers: HEADERS
```

### XML to JSON node {% new_in 3.13 %}

Transforms XML strings to JSON or a Lua table.

See the [configuration reference](/plugins/datakit/reference/#schema--config-nodes) and select `xml_to_json` from the node object dropdown to see all node attributes.

{:.info}
> **Note:** One of the `attributes_block_name` or `attributes_name_prefix` is required.

#### XML to JSON node inputs

The XML to JSON node accepts XML as input.

#### XML to JSON node outputs

The XML to JSON node outputs JSON strings or Lua tables.

#### Examples

If provided the following XML:

```xml
<root>
<name>Alice</name>
<age>30</age>
<is_student>false</is_student>
<courses>Math</courses>
<courses>Science</courses>
<address>
<street>123 Main St</street>
<city>Wonderland</city>
</address>
<null_value>null</null_value>
</root>
```

The XML to JSON node will output the following JSON:

```json
{
"root": {
"name": "Alice",
"age": 30,
"is_student": false,
"courses": ["Math", "Science"],
"address": {
"street": "123 Main St",
"city": "Wonderland"
},
"null_value": null
}
}
```

The configuration for the node would look like this:
```yaml
- name: CONVERT_XML_TO_JSON
type: xml_to_json
root_element_name: root
attributes_block_name: "#attr"
input: CALL_FOO
```

Where `CALL_FOO` is a call node that calls an API, and that API outputs XML.

For a more detailed example, see [Convert XML into JSON](/plugins/datakit/examples/convert-xml-into-json/).

For an example of using this node as part of a workflow, see [Transform JSON into XML and back](/plugins/datakit/examples/convert-json-to-xml-and-back/).

### JSON to XML node {% new_in 3.13 %}

Transforms JSON strings or Lua tables into XML.

See the [configuration reference](/plugins/datakit/reference/#schema--config-nodes) and select `json_to_xml` from the node object dropdown to see all node attributes.

{:.info}
> **Note:** One of the `attributes_block_name` or `attributes_name_prefix` is required.

#### JSON to XML node inputs

The JSON to XML node accepts JSON strings or Lua tables as input.

#### JSON to XML node outputs

The JSON to XML node outputs XML.

#### Examples

If provided the following JSON:
```json
{
"root": {
"name": "Alice",
"age": 30,
"is_student": false,
"courses": ["Math", "Science"],
"address": {
"street": "123 Main St",
"city": "Wonderland"
},
"null_value": null
}
}
```

The JSON to XML node will output the following XML:

```xml
<root>
<name>Alice</name>
<age>30</age>
<is_student>false</is_student>
<courses>Math</courses>
<courses>Science</courses>
<address>
<street>123 Main St</street>
<city>Wonderland</city>
</address>
<null_value>null</null_value>
</root>
```

The configuration for the node would look like this:
```yaml
- name: CONVERT_JSON_TO_XML
type: json_to_xml
root_element_name: root
attributes_block_name: "#attr"
input: CALL_BAR
```
Where `CALL_BAR` is a call node that calls an API, and that API outputs JSON.

For a more detailed example, see [Convert JSON into XML](/plugins/datakit/examples/convert-json-into-xml/).

For an example of using this node as part of a workflow, see [Transform JSON into XML and back](/plugins/datakit/examples/convert-json-to-xml-and-back/).

## Resources

Datakit supports a global `resources` object that can be used to declare shared resource configurations.
Expand Down
2 changes: 2 additions & 0 deletions app/_landing_pages/gateway/datakit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ rows:
- [`exit`](/plugins/datakit/#exit-node): Return directly to the client
- [`property`](/plugins/datakit/#property-node): Read and write {{site.base_gateway}} properties
- [`static`](/plugins/datakit/#static-node): Define static input values
- [`json_to_xml`](/plugins/datakit/#json-to-xml-node): Convert JSON data into XML format
- [`xml_to_json`](/plugins/datakit/#xml-to-json-node): Convert XML data into JSON format

Datakit also supports [implicit nodes](/plugins/datakit/#implicit-nodes) such as `request`, `response`, `vault`, and `service_request`, which represent gateway lifecycle events.
- blocks:
Expand Down
Loading