Can I use @QueryParam
when defining a DELETE operation? If yes, when I need to test it using jersey client, how the java code will look like? I tried something like
String result = client.target(url)
.queryParam("id",3)
.request(MediaType.APPLICATION_XML)
.delete(String.class);
But it was not working.
You can define a DELETE
endpoint using either @PathParam
(recommended) or @QueryParam
With @PathParam (recommended)
Endpoint: url/:id
@DELETE
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public void deletePathParam(@PathParam("id") int id) {
...
}
Test:
@Test
public void testDeletePathParam() {
Response output = target(url+"/3").request().delete();
// asserts
}
With @QueryParam (bad RESTapi design)
Endpoint: url?id=:id
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public void deleteQueryParam(@QueryParam("id") int id) {
...
}
Test:
@Test
public void testDeleteQueryParam() {
Response output = target(url).queryParam("id", 3).request().delete();
// asserts
}