Javatpoint Logo
Javatpoint Logo

Implementing a GET service to retrieve all Posts of a User

In this section, we will retrieve all the posts of a specific user.

Step 1: Open the UserJPAResource.java file and create a mapping for the URI "/jpa/users/{id}/posts"

Step 2: There is no need to show user detail in the response, so we will add @JsonIgnore annotation just above the User field in Post.java file.

Step 3: Open the Postman and send a GET request with the URI http://localhost:8080/jpa/users/{id}/posts. In our case, we have specified user id 101. It shows all the posts done by user 101.

Now, we send a GET request for the user who has not created any post yet. The user 105 has not created any post so we will specify this user id in the URI http://localhost:8080/jpa/users/105/posts.

It shows a pair of empty square brackets. The brackets denote that the user exists, but the user has not created any post.

Again send a GET request for the user who does not exist in the database say 110. It shows the Status: 404 Not Found with the following details:









Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA