Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass two query parameters in URL

In this example, the URL for a service has the form /projection/projectionId:

@Stateless
@Path("projection")
public class ProjectionManager {

@Inject
private ProjectionDAO projectionDAO;

@Inject
private UserContext userContext;

@GET
@Path("{projectionId}")
@Produces("application/json")
public String places(@PathParam("projectionId") String projectionId) {
    return projectionDAO.findById(Long.parseLong(projectionId)).getPlaces().toString();
}}

How can I pass two (or more) query parameters to access the service using this code:

@PUT
@Path("/buy")
public Response buyTicket(@QueryParam("projectionId") String projectionId, @QueryParam("place") String place) {
    Projection projection = projectionDAO.findById(Long.parseLong(projectionId));
    if(projection != null) {
        projectionDAO.buyTicket(projection, userContext.getCurrentUser(), Integer.parseInt(place));
    }

    return Response.noContent().build();
}
like image 381
alle3x Avatar asked Jun 17 '15 12:06

alle3x


1 Answers

/buy?projectionId=value1&place=value2

Take a look at https://en.wikipedia.org/wiki/Query_string for further information. And since it is HTTP PUT you cannot simply open that URL in your browser, you can write some simple REST client or use browser extension like Postman in Chrome.

like image 141
Tomasz W Avatar answered Oct 06 '22 04:10

Tomasz W