Jakarta RESTful Web Services, (JAX-RS; formerly Java API for RESTful Web Services) is a Jakarta EE API specification that provides support in creating web services according to the Representational State Transfer (REST) architectural pattern. JAX-RS uses annotations, introduced in Java SE 5, to simplify the development and deployment of web service clients and endpoints.
From version 1.1 on, JAX-RS is an official part of Java EE 6. A notable feature of being an official part of Java EE is that no configuration is necessary to start using JAX-RS. For non-Java EE 6 environments a small entry in the deployment descriptor is required.
Specification
JAX-RS provides some annotations to aid in mapping a resource class (a POJO) as a web resource. The annotations use the Java package <code>jakarta.ws.rs</code> (previously was <code>javax.ws.rs</code> but was renamed on May 19, 2019). They include:
- <code>@Path</code> specifies the relative path for a resource class or method.
- <code>@GET</code>, <code>@POST</code>, <code>@PUT</code>, <code>@PATCH</code> (since JAX-RS 2.1), <code>@DELETE</code>, <code>@HEAD</code> and <code>@OPTIONS</code> (since JAX-RS 1.1) specify the HTTP request type of a resource.
- <code>@Produces</code> specifies the response Internet media types (used for content negotiation).
- <code>@Consumes</code> specifies the accepted request Internet media types.
In addition, it provides further annotations to method parameters to pull information out of the request. All the <code>@*Param</code> annotations take a key of some form which is used to look up the value required.
- <code>@PathParam</code> binds the method parameter to a path segment.
- <code>@QueryParam</code> binds the method parameter to the value of an HTTP query parameter.
- <code>@MatrixParam</code> binds the method parameter to the value of an HTTP matrix parameter.
- <code>@HeaderParam</code> binds the method parameter to an HTTP header value.
- <code>@CookieParam</code> binds the method parameter to a cookie value.
- <code>@FormParam</code> binds the method parameter to a form value.
- <code>@DefaultValue</code> specifies a default value for the above bindings when the key is not found.
- <code>@Context</code> returns the entire context of the object (for example <code>@Context HttpServletRequest request</code>).
JAX-RS 2.0
In January 2011 the JCP formed the JSR 339 expert group to work on JAX-RS 2.0. The main targets are (among others) a common client API and support for Hypermedia following the HATEOAS-principle of REST. In May 2013, it reached the Final Release stage.
On 2017-08-22 JAX-RS 2.1 specification final release was published. Main new supported features include server-sent events, reactive clients, and JSON-B.
Implementations
Implementations of JAX-RS include:
References
External links
Tutorials
- https://javabrains.io/courses/javaee_jaxrs/
- http://docs.oracle.com/javaee/6/tutorial/doc/giepu.html
- http://www.vogella.com/tutorials/REST/article.html
- http://www.mkyong.com/tutorials/jax-rs-tutorials/
- http://www.coderpanda.com/jax-rs-tutorial/
- https://www.javavogue.com/2015/03/java-jerseyjax-rs-tutorials/
- http://howtodoinjava.com/restful-web-service/
- https://jakarta.ee/learn/starter-guides/how-to-build-a-restful-web-service/
- https://jakarta.ee/learn/starter-guides/how-to-secure-a-restful-web-service/
- https://jakarta.ee/learn/docs/jakartaee-tutorial/current/websvcs/rest/rest.html
- https://jakarta.ee/learn/specification-guides/restful-web-services-explained/