The $http service in AngularJS is used to make HTTP requests to external servers. It provides a convenient way to fetch data from APIs, submit forms, and interact with web services.
Key features of the $http service:
GET, POST, PUT, DELETE: Supports all common HTTP methods.
Promises: Returns a promise that resolves to the response data or rejects with an error.
Interceptors: Allows you to intercept requests and responses for custom handling.
Configuration: Provides options for configuring requests, such as headers, timeout, and authentication.
Example:
In this example, the $http service is used to make a GET request to the specified URL. The response data is then assigned to the $scope.data variable.
By using the $http service, you can easily interact with external APIs and fetch data for your AngularJS applications.