Created
October 6, 2017 13:29
-
-
Save gmittica/2a6f3f78b0832cde80c2f2edf86f85f8 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/bisugav
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="myApp"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<script src="https://rawgit.com/angular/bower-angular/master/angular.min.js"></script> | |
<title>JS Bin</title> | |
</head> | |
<body ng-controller="myCtrl"> | |
<script id="jsbin-javascript"> | |
angular.module("myApp", []) | |
.config(['$httpProvider', function($httpProvider) { | |
$httpProvider.interceptors.push(function() { | |
return { | |
request: function(config) { | |
console.log("My endpoint /" + config.url.split("/").pop()); | |
return config; | |
}, | |
responseError: function(response) { | |
console.log("NOOOO! Error " + response.status); | |
return response; | |
} | |
}; | |
}); | |
}]) | |
.run(['$http', function($http) { | |
$http.defaults.headers.common.Authorization = "Basic xyz"; | |
}]) | |
.service("ApiService", ['$http', function ($http) { | |
var service = {}; | |
service.getUsers = function() { | |
return $http.get('https://jsonplaceholder.typicode.com/usersxxx'); | |
}; | |
service.postUser = function(user) { | |
return $http.post('https://jsonplaceholder.typicode.com/users', user); | |
}; | |
return service; | |
}]) | |
.controller("myCtrl", ['ApiService', function (ApiService) { | |
ApiService.getUsers(); | |
}]) | |
; | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">angular.module("myApp", []) | |
.config(['$httpProvider', function($httpProvider) { | |
$httpProvider.interceptors.push(function() { | |
return { | |
request: function(config) { | |
console.log("My endpoint /" + config.url.split("/").pop()); | |
return config; | |
}, | |
responseError: function(response) { | |
console.log("NOOOO! Error " + response.status); | |
return response; | |
} | |
}; | |
}); | |
}]) | |
.run(['$http', function($http) { | |
$http.defaults.headers.common.Authorization = "Basic xyz"; | |
}]) | |
.service("ApiService", ['$http', function ($http) { | |
var service = {}; | |
service.getUsers = function() { | |
return $http.get('https://jsonplaceholder.typicode.com/usersxxx'); | |
}; | |
service.postUser = function(user) { | |
return $http.post('https://jsonplaceholder.typicode.com/users', user); | |
}; | |
return service; | |
}]) | |
.controller("myCtrl", ['ApiService', function (ApiService) { | |
ApiService.getUsers(); | |
}]) | |
; | |
</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module("myApp", []) | |
.config(['$httpProvider', function($httpProvider) { | |
$httpProvider.interceptors.push(function() { | |
return { | |
request: function(config) { | |
console.log("My endpoint /" + config.url.split("/").pop()); | |
return config; | |
}, | |
responseError: function(response) { | |
console.log("NOOOO! Error " + response.status); | |
return response; | |
} | |
}; | |
}); | |
}]) | |
.run(['$http', function($http) { | |
$http.defaults.headers.common.Authorization = "Basic xyz"; | |
}]) | |
.service("ApiService", ['$http', function ($http) { | |
var service = {}; | |
service.getUsers = function() { | |
return $http.get('https://jsonplaceholder.typicode.com/usersxxx'); | |
}; | |
service.postUser = function(user) { | |
return $http.post('https://jsonplaceholder.typicode.com/users', user); | |
}; | |
return service; | |
}]) | |
.controller("myCtrl", ['ApiService', function (ApiService) { | |
ApiService.getUsers(); | |
}]) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment