7
CREATING REST API USING MULE ESB Creating REST services using Mule ESB is quite easy as Mule is having built in support for Jersey. The next question would be what is Jersey ? How does it come into the picture when I am trying to work in Mule ESB. Jersey webservice framework is an open source framework for developing RESTful services in Java which support JAX-RS APIs. It supports in exposing our data in variety of representation media and removing that low level implementation details for client server communication. This is the basic understanding about REST API in Mule ESB.

Creating restful api using mule esb

Embed Size (px)

Citation preview

CREATING REST API USING MULE ESBCreating REST services using Mule ESB is quite easy as Mule is having built in support for Jersey.The next question would be what is Jersey ? How does it come into the picture when I am trying to work in Mule ESB.

Jersey webservice framework is an open source framework for developing RESTful services in Java which support JAX-RS APIs. It supports in exposing our data in variety of representation media and removing that low level implementation details for client server communication.

This is the basic understanding about REST API in Mule ESB.

HOW TO USE THIS INSIDE THE FLOW

We have to place our mule flow which contains an endpoint and a REST component.

The flow will look like below picture.

Inside the REST component of our flow we have place a Java file which will enable the implementation of RESTful services.

The configuration will look like below.

Now we have annotate our REST implementation class. I have created this class for the sake of example.

It will look like below.

CLASS LEVEL ANNOTATION

In JAX-RS, we can use @Path to bind URI pattern to a Java method.

If you see the code in the last page you will find that @Path("/schools") has been used.

This path sets the baseURI for the class which is implementing the RESTful API.

Now when we will make an HTTP request to this flow it will look like localhost:8084/schools.

Now this call will reach till the class level but will not proceed to any method.

METHOD LEVEL ANNOTATION

The @GET annotation is a request method designator and corresponds to the similarly named HTTP method.

The@Produces(MediaType.APPLICATION_JSON) depicts that the outcome from the method would be in JSON format.

The @Path("/{id}") annotation tells us that whatever value we will providing through as param will be retrieved.

FINAL REST CALL Now in the same example if hit the browser

with http://localhost:8084/schools/1 you will find the result as School Details are DPS, Hyderabad Kondapur in the browser.

Now similarly you can place http://localhost:8084/schools/2 and check the response.