Upload
jitendra-bafna
View
75
Download
0
Embed Size (px)
Citation preview
HOW TO CONSUME RESTFUL WEB SERVICE WITH MULESOFT ANYPOINT STUDIO
What is RESFful Web Service
REST stands for Representational State Transfer. (It is sometimes spelled "ReST".) It relies on a
stateless, client-server, cacheable communications protocol and in virtually all cases, the HTTP
protocol is used.
RESTful Web Services are basically REST Architecture based Web Services. Restful web services are
light weight, highly scalable and maintainable and are very commonly used to create APIs for
web-based applications.
Consume RESTful Web Service
You can use HTTP Request connector to consume RESTful web service. You need to specify host,
port and optionally a Host Path for connector configuration. For Endpoint, you need to specify
path and method. Place the HTTP Listener to the source in the flow to receive the input message.
Consume RESTful Web Service
Now you can place the HTTP Requestor component to Message Processor in flow and configure it.
Click on Add Connector Configuration and it will open another window. Specify the host, port and
optionally base path and press OK.
Consume RESTful Web Service
After pressing OK, set path and method under url settings as shown in below image.
Passing Argument To RESTful Web
Service
For HTTP Request endpoint, you can add parameter
URI parameters
Query parameters
Headers
Passing Argument To RESTful Web
Service
Now you will see how to pass URI parameters with HTTP Request endpoint. You can use flow
variable to catch the query parameter from input request properties of HTTP Listener.
Passing Argument To RESTful Web
Service
Then under HTTP Request endpoint, Click Add Parameter, select uri-param and specify name and
value. Set uri-param value to the dynamic value of Flow Variable that we have used to store
query parameter and name can be anything. In this example, we will use name=destination, so
our Path will become /essentials/united/flights/{destination} instead of
/essentials/united/flights/CLE.
Passing Argument To RESTful Web
Service
Now your value for destination is not hardcoded and it will be dynamic. It is not necessary to
always pick value from query parameter and store in Flow Variable.
Testing the Application
You can use Postman to test the application. So first deploy the application with Anypoint Studio
and run the application. We will send message to Mule application using HTTP GET method and
test url is http://localhost:8081/rest?dest=CLE
THANK YOU