Showing posts with label RESTEasy. Show all posts

REST Java Architecture

In this article I am going to walk you through the implementation of a complete client/server RESTful Java web application that fully conforms to the Representational State Transfer (REST) constraints. Restful web services are well suited for the creation of APIs to be exposed to the internet for later consumptions. These APIs provide access to the resources and functionality exposed by the web application and can be accessed by the Unified Resource Identifiers (URIs). RESTful architecture is designed to use a stateless communication protocol (HTTP) which makes the application more scalable both horizontally and vertically, load balanced and easier to deal with upon fail-overs.

What makes RESTful applications to be simple, lightweight and fast?

- Resource identification through URI: Global addressing space for resource and service discovery.
-Uniform interface: Resources are manipulated using a set of operations (CRUD - Create/Read/Update/Delete) determined by the standard HTTP methods (GET, POST, PUT, DELETE) to which the resource is responding.
- Self-descriptive messages: Content is decoupled in a way that it can be accessed in a variety of formats such as HTML, XML, JSON, plain text, etc.
- Stateful interaction through links.
Bearing the above summary regarding REST in mind, let’s get into more detail explaining all the components that will be part of the architecture:

- RESTEasy: RESTful framework fully complaint with the JAX-RS specification and therefore it ensures that our web services will follow the REST architectural pattern. This will allow us to create the different services that will make our application reachable from the internet.
- Google Guice: Dependency injection framework that helps our app to be more reusable, testable and maintainable. Moreover, with this in place, we ensure that all the amount of workload needed for complicated tasks such as the inversion of control and dependency injection are properly addressed and performed.
- MyBatis: Persistance framework in charge of managing and handling the Object relational model (ORM).
- SLF4J/Logback: Logback will be the framework chosen for all the logging tasks. Since it implements SLF4J, which is the logging facade, we can readily switch to other logging frameworks such as log4j making our app’s logging pretty flexible.

Figure 1: Diagram showing the software stack used for the architecture.

Now that we have a more clear view on the general picture, let’s get the ball rolling setting up the project. In order to have an organized build procedure and all the dependencies that our project will rely on we will be using Maven as the build automation tool. Given that, let’s start off by configuring all the Maven projects (different modules) that will compose our architecture.