Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using Angularjs http service - Example

DZone's Guide to

Using Angularjs http service - Example

· Integration Zone ·
Free Resource

SnapLogic is the leading self-service enterprise-grade integration platform. Download the 2018 GartnerMagic Quadrant for Enterprise iPaaS or play around on the platform, risk free, for 30 days.

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.

With SnapLogic’s integration platform you can save millions of dollars, increase integrator productivity by 5X, and reduce integration time to value by 90%. Sign up for our risk-free 30-day trial!

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}