Created
November 18, 2011 00:01
-
-
Save justinwalsh/1375033 to your computer and use it in GitHub Desktop.
jQuery helper for REST apis using the _method override option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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