Skip to content

Instantly share code, notes, and snippets.

@rfaisal
Last active August 29, 2015 13:56
Show Gist options
  • Save rfaisal/9176840 to your computer and use it in GitHub Desktop.
Save rfaisal/9176840 to your computer and use it in GitHub Desktop.
var _url = 'http://localhost:49811/'; // the api root url
var _sample_greeting = 'Hey, there!'; // a sample greeting
//get all, sample JSON response: [{"id":1,"content":"Hey!"},{"id":2,"content":"Morning!"}]
$.ajax({type: "GET", url: _url + 'api/greetings', success: function (_d) {/*do stuff with _d*/});
//create new
$.ajax({type: "POST", url: _url + 'api/greetings/', data: {'':_sample_greeting}});
//update the 1st greeting
$.ajax({type: "PUT", url: _url + 'api/greetings/?id=1', data: {'':_sample_greeting}});
//delete the 1st greeting
$.ajax({type: "DELETE", url: _url + 'api/greetings/?id=1'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment