I have an api rest about movies. I want to search movies by "name". How I should define the path? Error with the pathParam. It says it cannot resolve it.
@GET
@Path("/search?text=name")
@Produces(MediaType.APPLICATION_JSON)
public Response getMovieByName(@Context HttpServletRequest req,
@PathParam("name") String name) {
if (!checkLoggedIn(req)) {
throw new WebApplicationException("User not logged.");
}
return buildResponse(movieService.getMovieByName(name));
}
This is query parameter, not a path parameter. You should not include query parameters in your path. They will be given to you when sent by the client:
What you need to change is the annotation used to inject the parameter into your method (use
@QueryParam):The name value will be sent in the
nameparameter if the service is called with something like/search/?name=moviename