These are the basic operations you can do with $http:
$http.get()
: Accepts aURL and optionalconfig
object. Performs an HTTPGET
request.$http.head()
: Accepts a URL and optionalconfig
object. Performs an HTTPHEAD
request.$http.post()
: Accepts a URL, data object, and optionalconfig
object. Performs an HTTPPOST
request.$http.put()
: Accepts a URL, data object, and optionalconfig
object. Performs an HTTPPUT
request.$http.delete()
: Accepts a URL and optionalconfig
object. Performs an HTTPDELETE
request.$http.jsonp()
: Accepts a URL and optionalconfig
object. The callback name should be the stringJSON_CALLBACK
.$http.patch()
: Accepts a URL, data object, and optionalconfig
object. Performs an HTTPPUT
request.
Example of calling the get() method:
$http({ method: 'GET', url: 'http://localhost:8000' }); $http.get('http://localhost:8000');
You can easily chain promises to handle success or error returns from the server:
$http.get('http://localhost:8000') .success(function(data){ $scope.contacts = data; }) .error(function(){ window.alert('There was an error!'); });
Example of a post:
$http.post('http://localhost:8000', { name: 'Declan Proud', email: 'declan@example.com', ... });