Retrieve Custom Header from HTTP request

 

In this tutorial we will explain how we can retrieve custom header from HTTP request in Mule 4. We are sending the messageid and transactionid as custom header with http rest call

Create a project in Anypoint studio and configure the listener

Create the transform message and write the dataweave expression to retrieve the header values.

Retrieve Custom Header from HTTP request

Dataweave expression:

%dw 2.0
output application/json
---
{
  "message_id":attributes.Headers.'messageid',
  "transaction-id":attributes.Headers.'transactionid'
}

There is another way to retrieve the headers values

%dw 2.0
output application/json
---
{
  "message_id":attributes.Headers.messageid,
  "transaction-id":attributes.Headers.transactionid
}

 

Deploy the project and test from soapui

messageid and transactionid is passed as custom Header in below SOAP UI

Retrieve Custom Header from HTTP request

 

Sample application:retrieveheader sample application

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Shivchetan Sambaragimath
Shivchetan Sambaragimath
4 years ago

Hi,

I am trying to add a custom header to http response in Mule 4 through the outboundHeaders variable. The header is fileExtension.

When I hit the API through postman, I always get in lower case like fileextension.

I believe this is as per Mule 4 design to maintain the RFC standards (headers always in lower case).

In Mule 3, I get it in the way I expect.

Could you please let me know if we can override this functionality in HTTP Listener Config ?

Thanks in advance.

Thank you,
Shivchetan Sambaragimath

Prathima
Prathima
3 years ago

can i have this pdf formate. i required all topics as pdf i can easily practice.