How to make a jax-rs end point accept any type of http request?

266 views Asked by At

The title says it all.

Is there any request type annotation to do that?

Or is it enough to annotate the method with all the required types like @POST, @GET?

1

There are 1 answers

0
lefloh On BEST ANSWER

Short answer:

Yes, you can annotate a method with @OPTIONS, @HEAD, @GET, @POST, @PUT, @DELETE and the resource method should be called on all of these methods.

Long answer:

You should not! Every HTTP method has it's semantic. A @GET is a 'safe' method because it is intended for reading a resource. @POST and @DELETE for instance are 'unsafe' because they change the state of a resource.

The web works because people follow these rules. A web-crawler knows that he can safely do a @GET on every URI he knows. He would never do a @DELETE on a URI. If your method changes something on a @GET you might get problems.

Find more answers why you should not here: Rest Services conventions.