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)

Introduction to content types and content negotiation

In this section, we're going to take a look at using the @Produces and @Consumes annotations to specify the content types. We'll also learn about API versioning using custom content types, smart content negotiation using a quality from server factor, and how you can serve and upload binary content.

Let's switch to code and open our IDE. Let's take a look at the small REST service that we have prepared. As you already know, you can specify the @Produces or @Consumes annotations to specify what your REST service will consume as a content type and what content type your REST service will produce. What we do here is we specify application/json. This is what we usually do. We implement this method and return a simple Map with the status code ok. Using JAX-RS, we'll make sure that this Map is serialized...