From the course: Java EE: RESTful Service with JAX-RS 2.0

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Build a response

Build a response

From the course: Java EE: RESTful Service with JAX-RS 2.0

Start my 1-month free trial

Build a response

- [Speaker] The full responses are very convenient for the quick development of the simple rest API. However, for more complex APIs you'll find that you'll need more control over this behavior and this is where the response builder comes in to it's own. We have already seen how easy and intuitive it is to use, by using it to set values for properties such as the status code and the response body. Let's take a closer look at the response builder and what functionality it offers. We obtain a responsibility instance by calling one of the static method on the response class. Here are some of the static methods. They should be familiar to you as we already used them to set the response codes and response body. Notice that the all retainer response builder instance. We can use the response builder to further refine the response on the client. Let's see some examples. So you can pass a response status code to the status method. Here we are passing the code 204 and calling the build method…

Contents