Over a million developers have joined DZone.

Using Angularjs http service - Example

· Integration Zone

Is iPaaS solving the right problems? Not knowing the fundamental difference between iPaaS and dPaaS could cost you down the road. Brought to you in partnership with Liaison Technologies.

Here I will show a sample angularJs http get request.

$scope.loadCustomerDetails = function(customerId) {

		var responsePromise = $http.get('/customerDetails.htm',{
			params : {
				data : customerId
			}
		});

		responsePromise.success(function(data, status, headers, config) {
			
			$scope.custDetails = data;
			
		});
		responsePromise.error(function(data, status, headers, config) {
			alert("Request failed!");
		});

	};


loadCustomerDetails is an angularjs function which takes one argument - customerId. Within this function, we make an ajax request to a REST endpoint 'customerDetails.htm' . This endpoint return data in json format. We are using promise to catch the result. Promise is an interface for interacting with an object that represents the result of an action that is performed asynchronously, and may or may not be finished at any given point in time.

If the request is a success, then the control goes to the responsepromise.success() function else to the error function.

Hope you got an into to the angularjs http service.

Discover the unprecedented possibilities and challenges, created by today’s fast paced data climate and why your current integration solution is not enough, brought to you in partnership with Liaison Technologies.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}