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.

Create the resource methods

Create the resource methods

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

Start my 1-month free trial

Create the resource methods

- [Instructor] Resource methods perform the actions of the resource class and map to the HTTP methods. We know that to retrieve all the books in the BookStore application, we must make a GET request to the URI api/books. And to create a new book, we must make a POST request to the same URI but how do we program this functionality? Well, we do it with resource methods that we annotate with the appropriate HTTP method. So, to retrieve all the books in the application, we write a method that returns all the books and annotate it @GET. And to create a book resource, we annotate the method that creates a book, @POST. In the case of a creational method, such as a method that creates a new book, we must pass the resource object we want to create to the method. But before discussing this last point in more detail, let's go back to the code and create these methods. The first thing you should do, is to create the method that retrieves all the books in the application. So let's create a method…

Contents