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();
}
/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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With