A Preview of Jakarta REST (JAX-RS) 4.0 in Jakarta EE 11
Published on 13 Nov 2024
by Luqman SaeedThe latest version of Jakarta REST (formerly Java API for RESTful Web Services, aka JAX-RS), Jakarta REST 4.0, will bring some notable improvements and changes as part of Jakarta EE 11. This release focuses on modernizing the specification by removing legacy dependencies, enhancing developer convenience, and improving test coverage. Before exploring the key changes, let's first take 37K feet intro to JAX-RS for the new comers to the platform.
Quick Intro to Jakarta REST
Jakarta RESTful Web Services, commonly known as Jakarta REST or JAX-RS, provides a standardized, annotation-based API for building RESTful web services in Java. It's a key specification in the Jakarta EE umbrella specification, enabling the creation of scalable and interoperable web services using the REST architectural style.
Key features of Jakarta REST include:
- Annotation Driven: Use annotations like @Path, @GET, @POST, etc., to define resources and HTTP methods.
- Automatic Content Negotiation: Easily produce and consume various media types (JSON, XML, etc.) based on client requests.
- URI Template Support: Flexibly map URIs to resource methods using parameterized paths.
- Pluggable Providers: Extend the core functionality with custom entity providers, exception mappers, and filters.
- Client API: A fluent API for invoking RESTful services from Java applications.
- Async Processing: Support for non-blocking I/O in both the client and server implementations.
Jakarta REST allows you to focus on application logic while the underlying implementation handles the complexities of HTTP communication and resource management.
What’s New?
With that out of the way and context in mind, let's explore what's new in the upcoming Jakarta REST 4.0 in Jakarta EE 11.
Farewell to JAXB and ManagedBeans
A major goal of Jakarta REST 4.0 was to remove dependencies on older Jakarta EE (or rather J2EE era) technologies. To that end, the specification no longer has a hard dependency on Jakarta XML Binding (JAXB). This allows Jakarta REST to be used more flexibly in environments that don't require XML processing.
Additionally, support for ManagedBeans has been removed from the specification. With CDI (Contexts and Dependency Injection) now the preferred approach for managing beans in Jakarta EE, this removal simplifies the programming model.
Enhanced Developer Experience
Several additions aim to enhance the developer experience:
- A new convenience method for checking header value lists has been added, simplifying a common task when working with HTTP headers.
- The UriInfo interface now includes a getMatchedResourceTemplate() method, providing easier access to matched URI templates.
- Support for JSON Merge Patch (RFC 7396) has been added, offering a standardised way to partially update JSON resources.
Improved Multipart Support
The specification now includes a portable API for handling multipart/form-data, addressing a long-standing pain point working with file uploads and complex form submissions.
Clarifications and Consistency
The specification document has been updated to clarify Java SE support, ensuring a clear understanding of how Jakarta REST can be used in different environments.
Focus on Quality
A significant effort has gone into improving the Technology Compatibility Kit (TCK) for Jakarta REST:
- New tests have been added for the multipart/form-data API, ensuring consistent implementation across vendors.
- Test coverage for default ExceptionMappers has been expanded, verifying correct handling of exceptions.
- Additional tests validate the new convenience methods and other recent additions.
Moving to Java SE 17
Jakarta REST 4.0 now requires a minimum of Java SE 17. This allows the specification to take advantage of newer Java language features and improvements, and also to maintain alignment with the broader Jakarta EE platform.
Conclusions
Jakarta REST (JAX-RS) 4.0 represents a focused update that modernises the specification while maintaining backward compatibility. With the removal of legacy dependencies, improvements in developer ergonomics and enhancing test coverage, it paves the way for more efficient and flexible RESTful web services development in the Jakarta EE ecosystem.
As always, you are encouraged to review the full specification and contribute to the project. The improvements in Jakarta REST 4.0 demonstrate the Jakarta EE community's commitment to evolving the platform to meet the needs of modern enterprise Java development.
Related Posts
Payara Platform Community 7 Alpha 2: Your Gateway to Jakarta EE 11
Published on 03 Dec 2024
by Luqman Saeed
0 Comments
Jakarta EE Media & Community Challenge - Winning Entries: Part 3
Published on 25 Nov 2024
by Chiara Civardi
0 Comments
The Jakarta EE Media and Community Challenge initiated by Payara celebrates the innovation and creativity that thrives within the Jakarta EE community. Designed as a platform to inspire, educate and showcase collaboration, the competition ...