I'm using jersey API for some REST web services with apache Tomcat. I need to pass more than one parameter to a method so I decided to use @QueryParam annotation like this :
@GET
@Path("/date")
@Produces(MediaType.APPLICATION_JSON)
public Response getDate(@QueryParam("id") String Id, @QueryParam("inDate") String inDate)
{
...
}
when I call it like this everything works. But when I use annotaitions @POST or @PUT instead of @GET then it shows an error:
HTTP Status 405 - Method Not Allowed
message Method Not Allowed
description The specified HTTP method is not allowed for the requested resource (Method Not Allowed).
Is it possible to user this with POST or PUT and how?
Any help is appreciated.
' in the URL, path parameters come before the question mark sign. Secondly, the query parameters are used to sort/filter resources. On the other hand, path parameters are used to identify a specific resource or resources. You can't omit values in path parameters since they are part of the URL.
Is it OK to use query parameters in a PUT request? Absolutely. Query parameters are just another piece of the resource identifier.
POST should not have query param. You can implement the service to honor the query param, but this is against REST spec. "Why do you pass it in a query param?" Because, like for GET requests, the query parameters are used to refer to an existing resource.
Yes, you just need to make the request using POST or PUT. This can't be done via the URL - you'd need a specific client (for example the http resource firefox plugin) that can send requests with methods other than GET. Note that for POST you can also use @FormParam
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