Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Patch XmlHttpRequest support

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...

like image 853
dev.pus Avatar asked Jul 02 '12 06:07

dev.pus


People also ask

What is the HTTP PATCH method?

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).

How do I send a browser PATCH request?

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.

Is http PATCH idempotent?

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.

Can PATCH request have body?

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.


2 Answers

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.

like image 51
srquinn Avatar answered Oct 23 '22 12:10

srquinn


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.

like image 21
iwein Avatar answered Oct 23 '22 12:10

iwein