Web Services Using Anypoint Studio


MuleSoft – Web Services Using Anypoint Studio


”;


REST Web Service

The full form of REST is Representational State Transfer which is bound with HTTP. Hence, if you want to design an application to be used exclusively on the web, REST is the best option.

Consuming RESTful Web Services

In the following example, we will be using REST component and one public RESTful service provided by Mule Soft called American Flights details. It has various details but we are going to use GET:http://training-american-ws.cloudhub.io/api/flights that will return all flight details. As discussed earlier, REST is bound with HTTP, hence we need two HTTP components ― one is Listener and other is Request, for this application too. Below screenshot shows the configuration for HTTP listener −

Rest web Service

Configuring and passing arguments

The configuration for HTTP request is given below −

HTTP Request

Now, as per our workspace flow, we have taken logger so it can be configured as below −

Convert the Payload

In the message tab, we write code to convert the payload into strings.

Testing the Application

Now, save and run the application and go to POSTMAN to check the final output as shown below −

Testing the Application

You can see it gives the flight details by using REST component.

SOAP Component

The full form of SOAP is Simple Object Access Protocol. It is basically a messaging protocol specification for exchanging information in the implementation of web services. Next, we are going to use SOAP API in Anypoint Studio to access the information using web services.

Consuming SOAP-based Web Services

For this example, we are going to use public SOAP service whose name is Country Info Service which retains the services related to country information. Its WSDL address is: http://www.oorsprong.org/websamples.countryinfo/countryinfoservice.wso?WSDL

First, we need to drag SOAP consume in our canvas from Mule Palette as shown below −

Consuming SOAP

Configuring and Passing Arguments

Next, we need to configure HTTP request as done in above example as given below −

Passing Arguments

Now, we also need to configure the Web Service Consumer as shown below −

Web Service Consumer

At the place of WSDL Location, we need to provide the web address of WSDL, which is provided above (for this example). Once you give the web address, Studio will search for service, Port and Address by itself. You need not provide it manually.

Transfer Response from Web Service

For this, we need to add a logger in the Mule flow and configure it for giving the payload as shown below −

Transfer Responce

Responce from Web Service

Testing the Application

Save and run the application and go to Google Chrome for checking the final output. Type http://localhist:8081/helloSOAP (for this example) and it will show the country name by code as shown in the screenshot below −

Final Output

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *