thiru
thiru

Reputation: 1

How to determine a correct request method is executed in RESTful webservice?

I want to understand how a RESTful web service identifies if a correct request method is called.

For example, I have a REST service it exposes one operation which is of type GET. Assume a REST client has invoked the operation using a wrong request method(PUT).

In this scenario, how the service/framework identifies a correct request method is invoked?

I have gone through various posts to understand the scenario but I don't find any information.

Please let me know your comments.

Upvotes: 0

Views: 79

Answers (2)

Elliptical view
Elliptical view

Reputation: 3812

It's the http protocol not REST that checks headers, and reports back with an error code.

REST is sort of a strategy, not an implementation.

Hope this helps.

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 692181

The first line sent in an HTTP request looks like this:

GET /index.html HTTP/1.1

The HTTP request thus contains the HTTP method (POST, PUT, GET, etc.). The framework reads this method, and invokes the Java method that is mapped (thanks to annotations, or XML configuration, or whatever) to the URL (also contained in the HTTP request, as shown above) and the HTTP method. If none is found, then an error response is sent back (405 Method Not Allowed, if the resource is found, but with another method, or 404 if the resource is not found).

Upvotes: 2

Related Questions