-1

I have code that contains several different DELETE methods, one of which takes a parameter, or at least ideally it would take a parameter. However when I make this request, either through CURL or through a web client, it doesn't work. The other DELETE requests function fine and I've hard-coded in the parameter that I want to pass just to see if the call works and it does. I've tried this with both PathParam and QueryParam and neither works. Here's how I'm using the PathParams, which I'm pretty sure is correct, QueryParams looks very similar so I don't want to post that too.

@DELETE
@Path("/byId/{id}")
public void deleteById(@PathParam("id") String id)

And then essentially the same thing for QueryParams but obviously the path is different

From what I understand a lot of RESTful APIs ignore any kind of request body with a DELETE request, or treat it as a PUT or POST. Is there any way around this? Basically I have a database that contains several objects and I need to delete one based on a unique identifier, to be passed in by the client. If there is no way around this is there some other way that I could do it?

Its possible that I'm missing something obvious here as I've only been using Jersey for a few weeks now and up to this point had never even heard of the concept of RESTful services.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user2482879
  • 35
  • 1
  • 6
  • Please add your code to your question. –  Jul 24 '13 at 11:51
  • @Tichodroma There isn't really a lot of code I can add, except for maybe how Im using the PathParams and QuereyParams (moved code to question) – user2482879 Jul 24 '13 at 13:30
  • This should work. What exactly do you mean when you say "it doesn't work"? –  Jul 24 '13 at 13:32
  • @Thichodroma Its deleting from a database and it should delete based on the id or ids given in parameters, I make the call using the path parameters or with them added as a query string and the object with that id is not deleted from the database. Either the request is ignored or the parameters are ignored Im not sure which. Like I said I tried hardcoding in the id to the method to see if the id was correct or the code was functional and that worked fine – user2482879 Jul 24 '13 at 13:35
  • Try to examine the value of `id` before hitting the database. Is `id` `null`? –  Jul 24 '13 at 13:37
  • @Tichodroma, id is not null, it is the expected value as entered by the client – user2482879 Jul 24 '13 at 13:57
  • So the REST/JAX-RS part of your code. Now you must include some details of the database part. –  Jul 24 '13 at 14:07
  • Its a couch data-base, for testing purposes its stood up on a VM and Im port forwarding to the VM. This does seem to work fine because as I said putting the id directly into the web-app code removes the file as expected. This also seems to indicate that the request is not being ignored, but rather its being treated as something else. A number of sites pointed out that some APIs treat a DELETE with a request body as a POST. That is what I think is going on here, so I guess I'll have to find another way to send the parameters, and I have no idea where to begin doing that. – user2482879 Jul 24 '13 at 14:11
  • The `@PathParam` is correctly passed inside your method. There is nothing wrong with JAX-RS and `DELETE`. You don't have a problem with JAX-RS, you have a problem somewhere else. Please ask a different question or add much more detail to this one. –  Jul 24 '13 at 14:16
  • I wasnt really asking if anything was wrong or if I was doing anything wrong, I was asking if there was some other way to pass values to an http DELETE method, Im sorry if that wasn't clear, I'll re-ask the question more clearly, If someone could close this question that'd be lovely – user2482879 Jul 24 '13 at 14:20

1 Answers1

0

You can send information to a RESTful service as either headers, path param, query param or message body.

If all the values go through as expected there is no problem with jax-rs/jersey. Now you need to debug the code and fix your implementation. jax-rs will only match a DELETE call with the DELETE http method you have implemented.

It is then your responsibility to actually perform a DELETE operation of the resource within the method. jax-rs or jersey is not going to complain if you do not DELETE or if you do some other action within the method.

techuser soma
  • 4,766
  • 5
  • 23
  • 43