Book Image

Building RESTful Web Services with Java EE 8

By : Mario-Leander Reimer
Book Image

Building RESTful Web Services with Java EE 8

By: Mario-Leander Reimer

Overview of this book

Java Enterprise Edition is one of the leading application programming platforms for enterprise Java development. With Java EE 8 finally released and the first application servers now available, it is time to take a closer look at how to develop modern and lightweight web services with the latest API additions and improvements. Building RESTful Web Services with Java EE 8 is a comprehensive guide that will show you how to develop state-of-the-art RESTful web services with the latest Java EE 8 APIs. You will begin with an overview of Java EE 8 and the latest API additions and improvements. You will then delve into the details of implementing synchronous RESTful web services and clients with JAX-RS. Next up, you will learn about the specifics of data binding and content marshalling using the JSON-B 1.0 and JSON-P 1.1 APIs. This book also guides you in leveraging the power of asynchronous APIs on the server and client side, and you will learn to use server-sent events (SSEs) for push communication. The final section covers advanced web service topics such as validation, JWT security, and diagnosability. By the end of this book, you will have implemented several working web services and have a thorough understanding of the Java EE 8 APIs required for lightweight web service development.
Table of Contents (8 chapters)

Implementing web service clients with Java EE 8

In this section, we're going to take a look at the JAX-RS client APIs and how to implement web service clients. I'm going to show you how you can set up and configure a JAX-RS client instance. We'll use WebTarget and its builder to specify request behavior, resolve URI template parameters, do invocation in response handling, and use GenericType implementations to get unmarshalled typed collections:

Conceptual view of this section

So far, we've implemented our small library service, which supports books, authors, and loans, via a REST API. We'll then implement a library client which is a standalone client to get a list of books, unknown books, to create books, to get books with the returned URI, and so forth.

Let's switch to our IDE. We will create a small class called LibraryServiceClient, which is...