DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Scalable Support Request Analysis Using Embeddings, HDBSCAN, and Tiny LLMs
  • KV Cache Implementation Inside vLLM
  • When Retries Become a Denial-of-Wallet
  • The Bill You Didn't See Coming

Trending

  • Why LLM Pipelines Fail in Production and How Temporal and Kafka Fix Them
  • Building Internal Developer Platforms as Products: A Practical Guide for IDP Architects
  • The Tectonic AI Platform: A Framework for Taming App Sprawl and Data Fragmentation
  • Engineering Production Agentic Systems: Part 3: The Topology

Mule-HTTP Request and Response Example

Here, I'm going to explain handling HTTP requests and responses in Mule, using AnypointStudio version 6.0 and Mule version 3.8.

By 
Rajeshkumar D user avatar
Rajeshkumar D
·
Jul. 05, 16 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
30.7K Views

Join the DZone community and get the full member experience.

Join For Free

Here, I'm going to explain handling HTTP requests and responses in Mule, using AnypointStudio version 6.0 and Mule version 3.8.

(Used: HTTP Endpoint and Logger in the flow.)

1. Drag and drop the HTTP endpoint in the Mule flow and configure the HTTP listener configuration.

<http:listener-config doc:name="HTTP Listener Configuration" host="0.0.0.0" name="HTTP_Listener_Configuration" port="7000"/>


We are using port number 7000.

Map the listener configuration to the HTTP endpoint which we have created.

<http:listener config-ref="HTTP_Listener_Configuration" doc:name="Receive HTTP request" path="/*"/>


2. Read the request from the URL, will be using set payload to do that.

<set-payload doc:name="Set Payload" value="#[message.inboundProperties['http.request.path']]"/>


Using MEL (Mule Expression Language) to read the request from the URL -message.inboundProperties['http.request.path']

3. Print the message in the browser using logger.

<logger doc:name="Log the payload" level="INFO" message="http example #[message.payload]"/>


Execute the Mule application and check the console for the successful deployment.

Enter the below URL in the browser :

http://localhost:7000/testhttp

You will see the response printing in the browser: testhttp

In the above example, we are using two functions.

1. reading from HTTP request and returns to response

2. logs the request

Total Flow XML :

<?xml version="1.0" encoding="UTF-8"?>
<mule version="EE-3.8.0" xmlns="http://www.mulesoft.org/schema/mule/core" 
  xmlns:core="http://www.mulesoft.org/schema/mule/core" 
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
xmlns:http="http://www.mulesoft.org/schema/mule/http" 
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">   
<http:listener-config doc:name="HTTP Listener Configuration" host="0.0.0.0" name="HTTP_Listener_Configuration" port="7000"/>  
  <flow doc:name="HTTP Example" name="EchoFlow">       
    <http:listener config-ref="HTTP_Listener_Configuration" doc:name="Receive HTTP request" path="/*"/>       
    <set-payload doc:name="Set Payload" value="#[message.inboundProperties['http.request.path']]"/>   
    <logger doc:name="Log the payload" level="INFO" message="http example #[message.payload]"/>    
  </flow>
</mule>

That's all!

Requests

Opinions expressed by DZone contributors are their own.

Related

  • Scalable Support Request Analysis Using Embeddings, HDBSCAN, and Tiny LLMs
  • KV Cache Implementation Inside vLLM
  • When Retries Become a Denial-of-Wallet
  • The Bill You Didn't See Coming

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook