Skip to content

Service method path mapping

Ahmad K. Bawaneh edited this page Mar 16, 2020 · 3 revisions

Service method path mapping

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 for the 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
    void updateMovie(@BeanParam @RequestBody Movie movie);
}

the listMovies method will produce an http request to the following endpoint :

http://localhost:8080/service/library/movies

we can 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 result in the following http request path :

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.