When you are building out an API and integration with MuleSoft’s Anypoint Studio, you will need to capture custom headers, query parameters, and URI parameters from the HTTP request. Capturing this data is important and it’s extremely easy to capture using the Transform Message component and DataWeave. In the tutorial below, we are going to highlight how to retrieve custom headers, queries, and URI parameters from your HTTP request using DataWeave.
If you haven't already, make sure to sign up for a free Anypoint Platform account. Click the button below to create a free account.
When you send an HTTP request to your HTTP endpoint, you can capture the header data using a DataWeave script. In the case of the DataWeave script below, we will return the header information in the body of the response. You can use DataWeave to save these responses as variables, and pass them to other systems as needed.
You can see that after sending the POST request, we receive a 200 OK response from our mule application returning our desired response in JSON.
DataWeave makes it easy to capture query parameters and save them for later use within your integration. Use the attributes.queryParams reference in DataWeave to capture the query parameter sent in the request.
You can capture a URI parameter (also known as a Path Param) using DataWeave. A URI parameter identifies a specific resource whereas a Query Parameter is used to sort or filter resources. When you are setting up your HTTP listener, make sure to set up your endpoint using the curly brace notation to capture the variable element. Then use the DataWeave command attributes.uriParams to capture the URI parameter from the HTTP request.