Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you make a HTTP PATCH request from Javascript?

I am working with an API that requires me to make an HTTP PATCH request as part of the URI, is this possible to do from Javascript, my research is showing that I can only do POST, GET, DELETE, and PUT. Is PATCH allowed?

Thank you,

like image 940
NSA Avatar asked Sep 21 '11 15:09

NSA


1 Answers

I'm not sure what you exactly mean by a "PATCH" request, but it seems to be possible (at least in Firefox 6 and Chromium 12). According to the Mozilla source code, there is only a limitation of TRACE and TRACK requests.

A quick testcase:

<!-- test.html -->
<script>
var x=new XMLHttpRequest();
x.open("patch", "/");
x.send(null);
</script>

Any webserver can be used, but I choose for Python's SimpleHTTPServer module.

$ ls
test.html
$ python -m SimpleHTTPServer
localhost - - [21/Sep/2011 17:32:11] "GET /test.html HTTP/1.1" 200 -
localhost - - [21/Sep/2011 17:32:11] code 501, message Unsupported method ('patch')
localhost - - [21/Sep/2011 17:32:11] "patch / HTTP/1.1" 501 -

So, as long as the server supports the method, the request get's passed.

like image 96
Lekensteyn Avatar answered Sep 19 '22 15:09

Lekensteyn