Jack
Jack

Reputation: 1911

Resteasy @POST annotated method not called

I'm using Resteasy 2.3.5. The following @POST annotated method is never called, when I request its URL http://localhost:8080/MyApp/rest/echo/foobar in my browser:

@POST
@Path("/echo/{msg}")
@Produces("text/plain; charset=UTF-8")
public String echo(@PathParam("msg") final String msg) {
    return msg;
}

However, when I replace @POST by @GET it works just fine (the browser returns foobar). What is wrong?

Upvotes: 0

Views: 298

Answers (2)

Mark Jentz
Mark Jentz

Reputation: 161

The @POST annotation refers to the HTTP POST request method. Your web browser will normally only issue GET HTTP request methods, which is why your example works when you change to @GET. There are many tools you can use to help you test your REST service, some of them work form right inside your browser.

For Firefox try https://addons.mozilla.org/en-us/firefox/addon/restclient/

For Chrome try https://chrome.google.com/webstore/detail/rest-console/cokgbflfommojglbmbpenpphppikmonn?hl=en

You can also see What tools do you use to test your public REST API?

Upvotes: 1

Viccari
Viccari

Reputation: 9318

This happens because your browser will always do a GET request when you type a URL.
Try downloading a HTTP client tool like cURL. Then run the following test from your command line environment:

curl "http://localhost:8080/MyApp/rest/echo/foobar" -X POST

You can play around with any of the HTTP methods, headers, etc. Give it a try.

Upvotes: 2

Related Questions