The JaxRs annotation @Path is used to map each service method to an endpoint in the service alongside the http method, the path defined in the service method definition will be appended to matched service root of that service and can have variable parameters. for example the following service :
@RequestFactory
public interface MoviesService {
@Path("library/movies/:movieName")
@GET
Movie getMovieByName(@PathParam("movieName") String movieName);
@Path("library/movies")
@GET
List<Movie> listMovies();
@Path("library/movies/:name")
@PUT
@SuccessCodes({200})
void updateMovie(@beanParam @RequestBody Movie movie);
}
The listMovies method will make a request to the following endpoint http://localhost:8080/service/library/movies
Notice that we can also define a variable parameter in the method path by adding : before the name of the parameter or surround it with {}, the parameter name will be matched with the method argument name for replacement
for example : calling getMovieByName and pass the movie name hulk as argument will make a request to the following url http://localhost:8080/service/library/movies/hulk
if we are passing a request body in the method argument we can use that request properties to replace path variable parameters, the variable path parameter name will be match with the property name from the request pojo.
We can also use the @Path annotation on service level top define a root service path for the service methods presented in the service interface, for example instead of writing the service like this
MoviesServiceFactory.INSTANCE
.getMovieByName("hulk")
.onSuccess(movie ->{})
.send();
We can define it like this :
@Path("second-root-path")
public interface SecondService {
@Path("second-path")
SomeResponse secondRequest();
}