AngularJS $http
We use $http as a service to read data from remote servers. From AngularJS $http we make a request to the server and returns a response. Below is the example of $http request response model.
Methods
In above example we uses the .get method of $http service. And .get method is a
shortcut method of $http service. Below are the example of different shortcut methods
(i).delete()
(ii).get()
(iii).head()
(iv).jsonp()
(v).patch()
(vi).post()
(vii).put()
Above all methods are shortcuts of calling the $http service.
In above example it execute the $http service with an object as an argument. And object is specifying the HTTP method , URL and sucess and failure operation details.
Properties
The response we get from server is an object with these below properties:
(1).config:- the object used to generate the request.
(2).data:- it could be a string, or an object, carrying the response from the server.
(3).headers:- a function to use to get header information.
(4).status:- a number defining the HTTP status.
(5).statusText:- a string defining the HTTP status.
Below example will helps you get response with above properties.
To handle this errors we will add one more functions to the .then method
| |