smwikipedia
smwikipedia

Reputation: 64213

Why a browser only supports GET and POST HTTP methods?

I read the following text from Apress Apache Tomcat 7

The HttpServlet.service() method implementation is a convenient way to control access to your servlets in the code. For example, servlets that delete data from the database should always be accessed using the DELETE method, but because browsers only support GET and POST operations, the POST method should be used instead.

It seems most browsers only supports 2 HTTP methods, GET and POST.

If so, why?

Upvotes: 1

Views: 3070

Answers (2)

Rahul Tripathi
Rahul Tripathi

Reputation: 172458

There are modern browsers which allow GET, POST, PUT and DELETE using the XMLHttpRequest. You can go through this bug 10671

Executing PUT and DELETE to modify resources on the origin server is straight-forward for modern Web browsers using the XmlHttpRequest object. For unscripted browser interactions this not so simple. Typically, devs and frameworks end up creating work-arounds that mimic the HTTP PUT/DELETE + Etag interaction using a "POST FORM" coupled with specialized server-side code to sort out the special case and act as if the proper HTTP Method was used in the request

Other considerations:

  • Using POST as a tunnel instead of using PUT/DELETE can lead to caching mis-matches (e.g. POST responses are cachable5, PUT responses are not[6], DELETE responses are not[7])

  • Using a non-idempotent method (POST) to perform an idempotent operation (PUT/DELETE) complicates recovery due to network failures (e.g. "Is is safe to repeat this action?").

You can also refer this thread: Are the PUT, DELETE, HEAD, etc methods available in most web browsers?

Upvotes: 1

Guffa
Guffa

Reputation: 700372

In a form the only possible methods are GET and POST. When you make an AJAX call, other methods are supported.

<form>:

method = get|post [CI]
This attribute specifies which HTTP method will be used to submit the form data set. Possible (case-insensitive) values are "get" (the default) and "post".

XMLHttpRequest:

method
The HTTP method to use, such as "GET", "POST", "PUT", "DELETE", etc. Ignored for non-HTTP(S) URLs.

Upvotes: 3

Related Questions