11
HOW TO CONSUME RESTFUL WEB SERVICE WITH MULESOFT ANYPOINT STUDIO

How To Consume RESTful Web Service With MuleSoft Anypoint Studio

Embed Size (px)

Citation preview

Page 1: How To Consume RESTful Web Service With MuleSoft Anypoint Studio

HOW TO CONSUME RESTFUL WEB SERVICE WITH MULESOFT ANYPOINT STUDIO

Page 2: 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.

Page 3: How To Consume RESTful Web Service With MuleSoft Anypoint Studio

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.

Page 4: How To Consume RESTful Web Service With MuleSoft Anypoint Studio

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.

Page 5: How To Consume RESTful Web Service With MuleSoft Anypoint Studio

Consume RESTful Web Service

After pressing OK, set path and method under url settings as shown in below image.

Page 6: How To Consume RESTful Web Service With MuleSoft Anypoint Studio

Passing Argument To RESTful Web

Service

For HTTP Request endpoint, you can add parameter

URI parameters

Query parameters

Headers

Page 7: How To Consume RESTful Web Service With MuleSoft Anypoint Studio

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.

Page 8: How To Consume RESTful Web Service With MuleSoft Anypoint Studio

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.

Page 9: How To Consume RESTful Web Service With MuleSoft Anypoint Studio

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.

Page 10: How To Consume RESTful Web Service With MuleSoft Anypoint Studio

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

Page 11: How To Consume RESTful Web Service With MuleSoft Anypoint Studio

THANK YOU