Sub-resources
In JAX-RS, you can also introduce sub-resource functions in the same resources class. Use the @Path annotation to mark one or more functions to be a sub-resource of the original one; the new path will be relative to the original one. Let's see an example:
@Path("/hello")
public class FirstRest {
@Path("/path1")
@GET
public String testPath1() {
return "Hello from path 1!";
}
@Path("/path2")
@GET
public String testPath2() {
return "Hello from path 2!";
}
} As you can see, we have introduced the @Path annotation to the methods testPath1() and testPath2(). The new paths to those methods will be /hello/test1 and /hello/test2 respectively. You can test them using Postman, as we learned earlier.
And, for sure, we can choose the HTTP method of our choice for each of the sub-resource methods, as shown in the following example:
@Path("/hello")
public class FirstRest {
@Path("/path1")
@GET
public String testPath1...