I have these API calls which I need to do in my AngularJS controller.
Any example will be helpful.
app.post('/user/auth', users.auth);
app.get('/user/logout', helpers.isAuthenticated, users.logout);
What is API in AngularJS? API (Application Programming Interface) in AngularJS is a set of global JavaScript functions used for the purpose of carrying out the common tasks such as comparing objects, iterating objects, converting data. Some API functions in AngularJS are as follows : Comparing objects. Iterating ...
$http is an AngularJS service for reading data from remote servers.
You just need to make use of the $http
service like this:
angular.module('app', [])
.controller('ctrlname', ['$http', function($http){
//POST sample
$http.post('/user/auth', users.auth).then(function(response){
//handle your response here
});
//GET sample
//substitute 'param1' and 'param2' for the proper name the API is expecting these parameters
$http.get('/user/logout/?param1=' + helpers.isAuthenticated + '¶m2=' + users.logout).then(function(response){
//handle your response here
});
}]
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With