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
From the course: Java EE: RESTful Service with JAX-RS 2.0
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Define the REST contract3m 42s
-
(Locked)
Inheritance or XML configuration3m 25s
-
(Locked)
Define the API root3m 14s
-
Create the resource entity5m 37s
-
(Locked)
Create the resource methods6m 16s
-
(Locked)
Path parameters2m 35s
-
(Locked)
Add path paramaters3m 21s
-
@Consumes and @Produces2m 7s
-
(Locked)
Add the media types4m 56s
-
(Locked)
Challenge: Add resource methods31s
-
(Locked)
Solution: Add resource methods1m 56s
-
(Locked)
-
-
-
-