15

I am working on some todo app and would like to use the HTTP method PATCH to add and remove todo's because this would be semantically better than PUT.

In the backend I am using express.js (node.js) and in the front-end backbone.js (which uses jQuery for ajax).

I already tried if it actually works in back- and front-end on my local developement suite (Archlinux, Chromium 20, node.js 0.8, express 2.X) and it worked:

app.js

app.patch('/todo/:id', function(req, res){
    console.log('patch successfull');
}

chromium web console

$.ajax({ 
    url: '/messages/4ff13720f00e2e2c4b000006',
    type: 'PATCH',
    data: { body: 'that is a patched message' } 
});

The request was mentioned and also database actions where possible without exceptions.

I would now like to know how other browsers support the patch method. I looked with google but it is hard to find something because PATCH has multiple meanings...

dev.pus
  • 7,919
  • 13
  • 37
  • 51
  • 1
    "multiple meanings" including "browser patch", "eye patch", and "pirate patch". The first being the results that pop up most often. `:P` – Jared Farrish Jul 02 '12 at 06:26
  • This doesn't answer your question, but if you `use` the `express.methodOverride()` middleware, you can send a param called `_method` with your `POST` requests, and Express will route it to the method in the param (for example `_method=patch` would execute `app.patch`). – Michelle Tilley Jul 02 '12 at 06:30
  • Hi, I know, that is the only common way to sent PUTs and POST without Javascript. I just read in stackoverflow that XmlHttpRequests are independent from the http method patch but I am not sure about this – dev.pus Jul 02 '12 at 06:45
  • 2
    possible duplicate of [Are the PUT, DELETE, HEAD, etc methods available in most web browsers?](http://stackoverflow.com/questions/165779/are-the-put-delete-head-etc-methods-available-in-most-web-browsers) – Florian Margaine Oct 16 '12 at 15:59

2 Answers2

5

Most browsers restrict HTTP methods to GET/POST when applied to forms. However, with AJAX requests as long as the backend server can support the method it will work.

srquinn
  • 10,134
  • 2
  • 48
  • 54
2

Modern browsers do support PATCH (in fact with $ajax you can do any method you like, as long as the browser doesn't block it). Below IE9 you're out of luck.

With FF, Chrome and Safari it's less of an issue, because those started auto-updating years ago and more than two years ago they stopped blocking methods other than GET and POST.

iwein
  • 25,788
  • 10
  • 70
  • 111