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...
In computing, the PATCH method is a request method in HTTP for making partial changes to an existing resource. The PATCH method provides an entity containing a list of changes to be applied to the resource requested using the HTTP Uniform Resource Identifier (URI).
To send a PATCH request to the server, you need to use the HTTP PATCH method and include the request data in the body of the HTTP message. The Content-Type request header must indicate the data type in the body. In this PATCH request example, we send JSON to the ReqBin echo endpoint to update the data on the server.
A PATCH is not necessarily idempotent, although it can be. Contrast this with PUT ; which is always idempotent. The word "idempotent" means that any number of repeated, identical requests will leave the resource in the same state.
The PATCH HTTP method is used to modify the values of the resource properties. The PATCH HTTP method requires a request body. The body of the request must contain representation of the JSON Patch operations that you want to perform on the resource.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With