A utility module that provides a set of functions to interact HTTP body.
To use this module, you must import it to your DataWeave code, for example,
by adding the line import * from dw::io::http::BodyUtils
to the header of your
DataWeave script.
Name | Description |
---|---|
writeToBinary | Transforms the given HTTP body to a BinaryBodyType using:- contentType : to select the proper DataFormat- properties : the set of configuration properties specified by the DataFormat to write the current body. |
Name | Description |
---|---|
BinaryBodyType | DataWeave type for representing a Binary body.Supports the following fields: |
Transforms the given HTTP body to a BinaryBodyType
using:
contentType
: to select the proper DataFormatproperties
: the set of configuration properties specified by the DataFormat to write the current body.
A failure will be thrown if there is no valid DataFormat for the given contentType
value.
Name | Type | Description |
---|---|---|
body | HttpBody |
The HTTP request body to transform to a Binary value. |
contentType | String |
The Content-Type used to select the proper DataFormat. |
properties | Object |
The set of configuration properties specified by the DataFormat to write the current body. |
This example transforms a JSON HTTP request body to a BinaryBodyType
value.
%dw 2.0
import * from dw::io::http::BodyUtils
import * from dw::io::http::Client
output application/json
---
{
json: writeToBinary({name: "Mariano", lastname: "Lischetti"}, DEFAULT_SERIALIZATION_CONFIG.contentType, DEFAULT_SERIALIZATION_CONFIG.writerProperties)
}
{
"json": {
"body": "{\n \"name\": \"Mariano\",\n \"lastname\": \"Lischetti\"\n}",
"mime": {
"type": "application",
"subtype": "json",
"parameters": {}
}
}
}
This example transforms a Multipart HTTP body to a BinaryBodyType
value using the boundary
writer configuration.
%dw 2.0
import * from dw::io::http::BodyUtils
import * from dw::module::Multipart
output application/json
---
{
multipart: writeToBinary(
form([
field('field', 'value'),
field({name: 'field2', value:'value2'})]), "multipart/form-data", {boundary: "boundary"})
}
{
"multipart": {
"body": "--boundary\r\nContent-Disposition: form-data; name=\"field\"\r\n\r\nvalue\r\n--boundary\r\nContent-Disposition: form-data; name=\"field2\"\r\n\r\nvalue2\r\n--boundary--\r\n",
"mime": {
"type": "multipart",
"subtype": "form-data",
"parameters": {
"boundary": "boundary"
}
}
}
}
DataWeave type for representing a Binary
body.
Supports the following fields:
body
: Represents theBinary
body.mime
: Represent the bodyMimeType
.
{ body: Binary, mime: MimeType }