The $http
service is the primary service for making an AJAX request in AngularJS. The $http
service provides an API to perform all HTTP operations (actions) such as GET
, POST
, PUT
, DELETE
, and some others.
HTTP communication is asynchronous in nature. When making HTTP requests, a browser does not wait for the response to arrive before continuing processing. Instead, we need to register some callback functions that are invoked in the future when the response arrives from the server. The AngularJS Promise API helps us streamline this asynchronous communication and we use it extensively while working with the $http
service, as you will see later in this chapter.
The basic $http
syntax is:
$http(config)
The $http
service takes a configuration object as a parameter and returns a promise. The config
object contains a set of properties that affect the remote request behavior. These properties include arguments such as the HTTP action type (GET
, POST
, PUT
,…), the remote server URL...