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.
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 −
The configuration for HTTP request is given below −
Now, as per our workspace flow, we have taken logger so it can be configured as below −
In the message tab, we write code to convert the payload into strings.
Now, save and run the application and go to POSTMAN to check the final output as shown below −
You can see it gives the flight details by using REST 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.
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 −
Next, we need to configure HTTP request as done in above example as given below −
Now, we also need to configure the Web Service Consumer as shown below −
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.
For this, we need to add a logger in the Mule flow and configure it for giving the payload as shown below −
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 −