Jump to content

Jakarta RESTful Web Services

From Alfawiki
Jakarta RESTful Web Services (JAX-RS)
Company typeAPI standard
IndustrySoftware, Web services
PredecessorJava API for RESTful Web Services
FounderSun Microsystems
Area served
Worldwide
ProductsRESTful web services API
OwnerEclipse Foundation

Jakarta RESTful Web Services (JAX-RS; previously known as Java API for RESTful Web Services) is a Jakarta EE API standard designed to facilitate the development of web services that adhere to the Representational State Transfer (REST) architectural style. Originally created by Sun Microsystems and currently overseen by the Eclipse Foundation, JAX-RS leverages annotations introduced in Java SE 5 to streamline both the creation and deployment of web service endpoints and clients.

Starting with version 1.1, JAX-RS has been integrated into Java EE 6 as a standard component, allowing compliant platforms to launch with no configuration needed. For environments that do not support Java EE 6, a small amount of setup is necessary.

Specification

The JAX-RS specification offers a set of annotations within the jakarta.ws.rs package (which replaced javax.ws.rs in 2019) that bind Plain Old Java Object (POJO) resource classes to web resources. Notable annotations include:

  • @Path: assigns a relative URI path to a resource class or method.
  • HTTP method annotations: @GET, @POST, @PUT, @PATCH (introduced in 2.1), @DELETE, @HEAD, and @OPTIONS (available since 1.1).
  • @Produces: indicates the media types that the resource can return.
  • @Consumes: defines the media types accepted by the resource.

Parameter annotations are used to extract specific parts of incoming requests:

  • @PathParam, @QueryParam, @MatrixParam, @HeaderParam, @CookieParam, and @FormParam link method parameters to corresponding request components.
  • @DefaultValue: provides fallback values when parameters are absent.
  • @Context: injects contextual information such as HTTP request objects.

These capabilities enhance the efficiency of building RESTful services within enterprise Java platforms.

JAX-RS 2.0

In January 2011, the Java Community Process established the JSR 339 expert group tasked with creating JAX-RS 2.0, emphasizing a unified client API and support for Hypermedia following the HATEOAS constraint of REST. The specification was officially released in May 2013.

The JAX-RS 2.1 update was completed on August 22, 2017, adding functionalities such as server-sent events, reactive client support, and integration with JSON-B.

Implementations

Prominent implementations of JAX-RS encompass:

External links

Tutorials