17

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,

NSA
  • 5,689
  • 8
  • 37
  • 48
  • 1
    Most browsers limit the HTTP Methods to POST/GET, support for others are patchy, for instance IE9 does Delete, I haven't seen it in every browser however. For best results, re-phrase your question about browser support for HTTP Methods. – Incognito Sep 21 '11 at 15:42
  • 5
    Browser limits to POST/GET apply to HTML form submission, not XmlHttpRequest. – Julian Reschke Sep 21 '11 at 20:11

2 Answers2

5

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.

Lekensteyn
  • 64,486
  • 22
  • 159
  • 192
  • 1
    True. There are a few legacy browsers that may have problems with "extension" methods; Microsoft fixed this either in IE8 or in IE9. In older IEs, you can fall back to the XHR ActiveX object which doesn't have that limitation. – Julian Reschke Sep 21 '11 at 20:13
-2

As of some research the PATCH method seems to be new (march 2010 https://www.rfc-editor.org/rfc/rfc5789) so if you try to define PATCH on an XMLHttpRequest it may work, but only on very latest revisions of modern browsers. Don't have a supported browser list found, yet.

Community
  • 1
  • 1
sod
  • 3,804
  • 5
  • 22
  • 28
  • 6
    Not correct. A browser doesn't need to "know" a method in order to support it in XmlHttpRequest. – Julian Reschke Sep 21 '11 at 20:12
  • 1
    @JulianReschke the implementation of XHR (not the activeX flavor) in IE8 doesn't support the PATCH method. – Knu Oct 01 '15 at 06:02