Skip to content

Instantly share code, notes, and snippets.

@justinwalsh
Created November 18, 2011 00:01
Show Gist options
  • Save justinwalsh/1375033 to your computer and use it in GitHub Desktop.
Save justinwalsh/1375033 to your computer and use it in GitHub Desktop.
jQuery helper for REST apis using the _method override option
// Example usage
// api.put('/people', {name: 'John'}, function(response) { console.log(response); });
var api = {
url : "http://api.example.com",
get : function(url, data, callback) {
$.getJSON(api.url + url, data, callback);
},
post : function(url, data, callback) {
data._method = 'POST';
$.getJSON(api.url + url, data, callback);
},
put : function(url, data, callback) {
data._method = 'PUT';
$.getJSON(api.url + url, data, callback);
},
del : function(url, data, callback) {
data._method = 'DELETE';
$.getJSON(api.url + url, data, callback);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment