Skip to content

Body Manipulation And Generation

The body generator modifier allows you to craft the body you send to a backend through templates and enables injecting other values from the user request, such as the original body, headers, query strings, or URL parameters.

The body generator does not necessarily need that the endpoint sends data, as it works even when there is no input body from the user. It lets you specify the body content you want to send to the final service, and you can reuse parts of the request (such as headers) to form a new body.

The most common uses cases are:

Body manipulation or transformation

Add headers, token claims, or query strings to the body

Convert a backend POST into a GET endpoint while still sending data

Enrich the user’s body with additional data

Step 1. Click on API and create a new endpoint and provide the fields and click on create.

Field Sample Value
EndpointName Createaccont
Contextpath /createaccount
Method Method of endpoint you are exposing
Field Sample Value
Host* Backend endpoint Host(https://dummyjson.com)
URL* Context path after host(/products/add)
Type RestAPI , Rest To SOAP , AMQP Producer, AMQP Consumer, AWS Lambda
Method Method of Backend endpoint(GET)
Decode as Type of Response like (XML, JSON, No-op, String)

Publisher Portal API Overview

Step 2.

curl --location 'https://dummyjson.com/products/add' \
--header 'Content-Type: application/json' \
--data '{
    "title": "john"
}'

Response from the Backend Endpoint

{    
    "id":195,
    "title":"john"
}

{{

}}

Step 3.Click on the designer, select the type of security to which we want api to be secured.

{{

}}

Step 4.Click on + symbol in datatype and provide the expected response body and click on save

{{

}}

{{< prism lang="html" >}} Name:createaccountresponse

Example: {

"id":195,

"title":"john"

} {{< /prism >}}

{{

}}

Step 5.Provide the request body since it is POST request we need to define Request body in Datatype

{{< prism lang="html" >}} {

"update":
{

    "data":{

        "title":"john

    }
}

} {{< /prism >}} Step 6.Provide the Name and The response structure inside the Example and click on save.

{{

}}

Step 7.Select the + symbol on the Request body and Response Body select the data type created in the previous step as shown in below image. {{

}}

Step 8.Select the + symbol on the response body you can see Right side and select the data type created in the previous step as shown in below image, Provide the required fields like

Response Status code,

Media Type,

Description & Type(Datatype created in previous step)

Step 9.After providing details click on "save"

{{

}}

Step 10.click on endpoint ==> Backend>Request and then enable Body Manipulation and Generation as shown in below image.

{{

}}

Step 11.Click on Backend check the backend host and url method request {{

}}

{{

}}

Step 12.After enabling the Body Manipulation and Generation , provide the template body to transform the request payload in the desired format in which endpoint is expecting and then click on save as shown in below image.

{{< prism lang="html" >}} Body Editor:

{

"titile": "{{.req_body.update.data.title }}",

}

Conent-Type : application/json

Debug: true (Click on the check box) {{< /prism >}}

{{

}}

Step 13.Click on Deployment and click on Deploy, select the gateway you want to deploy and click on Deploy.

{{

}}

{{

}}

Step 14.Navigate to Devportal and login with the credentials of the consumer to which api is subscribed.

Step 15.You can visible as shown below images click on created api. {{

}}

Step 16.You will be able to see documnets and tryit click on "tryit" choose the API Product.

{{

}}

Step 17.Once you click on Try it and click on Get Access Token you can able to see the available resources to Test .

{{

}}

{{

}}

Step 18.Once the token is generated you can able to see the available resources to Test, now lets test one resource

{{

}}

Step 19.Click on "Try it Out" then "execute" {{

}}

{{

}}

Step 20.You can see the backend response {{

}}