In this blog, we will cover
- What is JAX-RS
- JAX-RS Specification
- Implementation provider for JAX-RS
- Why follow JAX-RS
What is JAX-RS
- JAX-RS: Java API for RESTful Web Services (JAX-RS) is a Java programming language API spec that provides support in creating web services according to the Representational State Transfer (REST) architectural pattern.
- JAX-RS 2.0 was released in May 2013.
- JAX-RS 2.1 was released in Sep 2017.
- JAX-RS provides some annotations to aid in mapping a resource class (a POJO) as a web resource.
- The annotations use the Java package javax.ws.rs.
- Following are the Annotations provided
Implementation provider for JAX-RS
- Apache CXF, an open-source Web service framework
- Jersey, the reference implementation from Oracle
- RESTeasy, JBoss’s implementation
- and many more…
Why follow JAX-RS
- I will show you a piece of code that expose REST Api for JBoss, GlassFish, and Web Server.
- As stated above, JAX-RS is specification or in short, it defines some standard/rules that make it easy to create a RESTful service that can be deployed to any Java application server like Glassfish, Jboss, Apache Tomee.
- Let’s say you developed an Application without using JAX-RS standard and happily running it in Jboss.
- Tomorrow you have a new requirement to move your application to GlassFish.
- In this case, you will have to rewrite your REST APIs logic again.
- Now consider the same scenario and assume you would have written your REST API using RESTEasy jar (JAX-RS implementation for Jboss).
- Now when you shift to GlassFish all you have to do is change implementation jar (Jersey JAX-RS implementation for Glassfish).
- Here is Sample Code
For Web Application (Jetty)
- See pom.xml for all three blocks.
- You will see different jars for JAX-RS implementation but there is no change in Code.
- That’s the benefit of following a specification. eg: JPA