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 which 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 makes it easy to create a RESTful service that can be deployed to any Java application server like GlassFish, Jboss, Apache Tomee.
- Lets say you developed an Application without using JAX-RS standard and happily running it in Jboss.
- Tomorrow you have new requirement to move your application to GlassFish.
- In this case you will have to rewrite your REST APIs logic again.
- Now consider 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 benefit of following a specification. eg: JPA