Jakarta RESTful Web Services, (JAX-RS; formerly Java API for RESTful Web Services) is a
Jakarta EE API
An application programming interface (API) is a connection between computers or between computer programs. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how to build ...
specification that provides support in creating
web service
A web service (WS) is either:
* a service offered by an electronic device to another electronic device, communicating with each other via the Internet, or
* a server running on a computer device, listening for requests at a particular port over a n ...
s according to the
Representational State Transfer
REST (Representational State Transfer) is a software architectural style that was created to describe the design and guide the development of the architecture for the World Wide Web. REST defines a set of constraints for how the architecture of ...
(REST) architectural pattern. JAX-RS uses
annotation
An annotation is extra information associated with a particular point in a document or other piece of information. It can be a note that includes a comment or explanation. Annotations are sometimes presented Marginalia, in the margin of book page ...
s, 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
Jakarta EE, formerly Java Platform, Enterprise Edition (Java EE) and Java 2 Platform, Enterprise Edition (J2EE), is a set of specifications, extending Java SE with specifications for enterprise features such as distributed computing and web serv ...
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
A Java package organizes Java classes into namespaces,
providing a unique namespace for each type it contains.
Classes in the same package can access each other's package-private and protected members.
In general, a package can contain the fo ...
jakarta.ws.rs
(previously was
javax.ws.rs
but was renamed on May 19, 2019). They include:
*
@Path
specifies the relative
path
A path is a route for physical travel – see Trail.
Path or PATH may also refer to:
Physical paths of different types
* Bicycle path
* Bridle path, used by people on horseback
* Course (navigation), the intended path of a vehicle
* Desir ...
for a resource class or method.
*
@GET
,
@POST
,
@PUT
,
@PATCH
(since JAX-RS 2.1),
@DELETE
,
@HEAD
and
@OPTIONS
(since JAX-RS 1.1) specify the
HTTP request type of a resource.
*
@Produces
specifies the response
Internet media type
In information and communications technology, a media type, content type or MIME type is a two-part identifier for file formats and content formats. Their purpose is comparable to filename extensions and uniform type identifiers, in that they ident ...
s (used for
content negotiation
In computing, content negotiation refers to mechanisms defined as a part of HTTP that make it possible to serve different versions of a document (or more generally, representations of a resource) at the same URI, so that user agents can specify w ...
).
*
@Consumes
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
@*Param
annotations take a key of some form which is used to look up the value required.
*
@PathParam
binds the method parameter to a path segment.
*
@QueryParam
binds the method parameter to the value of an HTTP
query parameter.
*
@MatrixParam
binds the method parameter to the value of an
HTTP matrix parameter.
*
@HeaderParam
binds the method parameter to an
HTTP header
HTTP header fields are a list of strings sent and received by both the client program and server on every HTTP request and response. These headers are usually invisible to the end-user and are only processed or logged by the server and client ...
value.
*
@CookieParam
binds the method parameter to a
cookie
A cookie is a sweet biscuit with high sugar and fat content. Cookie dough is softer than that used for other types of biscuit, and they are cooked longer at lower temperatures. The dough typically contains flour, sugar, egg, and some type of ...
value.
*
@FormParam
binds the method parameter to a
form
Form is the shape, visual appearance, or configuration of an object. In a wider sense, the form is the way something happens.
Form may also refer to:
*Form (document), a document (printed or electronic) with spaces in which to write or enter dat ...
value.
*
@DefaultValue
specifies a
default value for the above bindings when the key is not found.
*
@Context
returns the entire context of the object (for example
@Context HttpServletRequest request
).
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
Hypermedia as the engine of application state (HATEOAS) is a constraint of the REST software architectural style that distinguishes it from other network architectural styles.
With HATEOAS, a client interacts with a network application whose appl ...
-principle of
REST
REST (Representational State Transfer) is a software architectural style that was created to describe the design and guide the development of the architecture for the World Wide Web. REST defines a set of constraints for how the architecture of ...
. 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
Server-Sent Events (SSE) is a server push technology enabling a client to receive automatic updates from a server via an HTTP connection, and describes how servers can initiate data transmission towards clients once an initial client connection ha ...
,
reactive clients,
and JSON-B.
Implementations
Implementations of JAX-RS include:
*
Apache CXF
Apache CXF is an open source software project developing a Web services framework. It originated as the combination of Celtix developed by IONA Technologies and XFire developed by a team hosted at the now defunct host CodeHaus in 2006. These two ...
, an open source
Web service
A web service (WS) is either:
* a service offered by an electronic device to another electronic device, communicating with each other via the Internet, or
* a server running on a computer device, listening for requests at a particular port over a n ...
framework
*
Jersey, the
reference implementation
In the software development process, a reference implementation (or, less frequently, sample implementation or model implementation) is a program that implements all requirements from a corresponding specification. The reference implementation ...
from
Sun
The Sun is the star at the centre of the Solar System. It is a massive, nearly perfect sphere of hot plasma, heated to incandescence by nuclear fusion reactions in its core, radiating the energy from its surface mainly as visible light a ...
(now
Oracle
An oracle is a person or thing considered to provide insight, wise counsel or prophetic predictions, most notably including precognition of the future, inspired by deities. If done through occultic means, it is a form of divination.
Descript ...
)
RESTeasy JBoss
WildFly, formerly known as JBoss AS, or simply JBoss, is an application server written by JBoss, now developed by Red Hat. WildFly is written in Java and implements the Java Platform, Enterprise Edition (Java EE) specification. It runs on mult ...
's implementation
*
Restlet
*
WebSphere Application Server from
IBM
International Business Machines Corporation (using the trademark IBM), nicknamed Big Blue, is an American Multinational corporation, multinational technology company headquartered in Armonk, New York, and present in over 175 countries. It is ...
:
** Version 7.0: via th
"Feature Pack for Communications Enabled Applications"** Version 8.0 onwards: natively
*
WebLogic Application Server from
Oracle
An oracle is a person or thing considered to provide insight, wise counsel or prophetic predictions, most notably including precognition of the future, inspired by deities. If done through occultic means, it is a form of divination.
Descript ...
, se
notes* Apache Tuscany (http://tuscany.apache.org/documentation-2x/sca-java-bindingrest.html), discontinued
* Cuubez framework (https://web.archive.org/web/20190707005602/http://cuubez.com/)
Everrest Codenvy's Implementation
Jello-Framework Java Application Framework optimized for Google App Engine, including a powerful RESTful engine and comprehensive Data Authorization model.
*
Apache TomEE
Apache TomEE (pronounced "Tommy") is the Enterprise Edition of Apache Tomcat (Tomcat + Java/Jakarta EE = TomEE) that combines several Java enterprise projects including Apache OpenEJB, Apache OpenWebBeans, Apache OpenJPA, Apache MyFaces and o ...
, an addition to
Apache Tomcat
Apache Tomcat (called "Tomcat" for short) is a free and open-source implementation of the Jakarta Servlet, Jakarta Expression Language, and WebSocket technologies. It provides a "pure Java" HTTP web server environment in which Java code can also ...
References
* Hadley, Marc and Paul Sandoz, eds. (September 17, 2009).
JAX-RS: Java API for RESTful WebServices' (version 1.1),
Java Community Process
The Java Community Process (JCP), established in 1998, is a formal mechanism that enables interested parties to develop standard technical specifications for Java technology. Becoming a member of the JCP requires solid knowledge of the Java program ...
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/
{{Jakarta RESTful Web Services
Java enterprise platform
Java API for XML
Web service specifications