2. REST stands for REpresentational State Transfer. It relies on HTTP for
transport and uses HTTP methods to perform operations on remote
Services. HTTP’s GET method would be for Read, POST for Create,
PUT for Update
REST has many advantages and many companies are adapting it
as Integration standard. However, one area it still needs
improvement is Security. Traditionally REST services can use
standard HTTP/S security (SSL/Mutual Authentication etc.,).
3. Mule ESB supports REST through Jersey (JAX-RS) implementation.
Lets build a example that demonstrates the use of REST component
in Mule Studio. Open “Mule Training” project and create a Mule
flow named “restexample”. Drag and drop a HTTP endpoint and specify
“localhost”, “8081” and “rest” as Host, Port and Path parameters as shown
below.
6. Create a simple Java class called “HelloRESTService” with a method
“sayHelloWithUri” as follows.
package restexample;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
7. @Path(value = "/rest")
public class HelloRestService {
@POST
@Produces("text/plain")
@Path("/{name}")
public String sayHelloWithUri(@PathParam("name") String name) {
return "Hello " + name;
}
}
8. The bulk of work in REST is component creation. Mule flow will only have
a HTTP endpoint followed by REST component. Remaining hardwork is
done by JAX-RS.
Drag and drop and REST component next to HTTP endpoint.
Specify
“training.rest.HelloRESTService” for Class attributed of REST
component as shown below.
9.
10. Save and run the project.
Access http://localhost:8081/rest/Antonio. Output,
which is nothing but return value from “sayHello”
method will be displayed.