Created
October 6, 2017 10:21
-
-
Save gmittica/50e314cac0e725230318ca649364c068 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", []) | |
.service("ApiService", ['$http', function ($http) { | |
// 'https://jsonplaceholder.typicode.com/users' | |
var service = {}; | |
service.postUser = function(user) { | |
return $http.post('https://jsonplaceholder.typicode.com/usexxrs', user); | |
}; | |
return service; | |
}]) | |
.controller("myCtrl", ['ApiService', function (ApiService) { | |
ApiService.postUser({username: 'Joker'}).then(function(response) { | |
console.log(response.config); | |
}, function(response) { | |
console.log(response.status); | |
}); | |
}]) | |
.config(['$httpProvider', function($httpProvider) { | |
$httpProvider.interceptors.push(function() { | |
return { | |
'request': function(config) { | |
var url = config.url.split("/"); | |
var params = config.params; | |
console.log("ENDPOINT /" + url[url.length-1]); | |
if(params) { | |
console.log("PARAMS ", params); | |
} | |
return config; | |
} | |
} | |
}) | |
}]); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">angular.module("myApp", []) | |
.service("ApiService", ['$http', function ($http) { | |
// 'https://jsonplaceholder.typicode.com/users' | |
var service = {}; | |
service.postUser = function(user) { | |
return $http.post('https://jsonplaceholder.typicode.com/usexxrs', user); | |
}; | |
return service; | |
}]) | |
.controller("myCtrl", ['ApiService', function (ApiService) { | |
ApiService.postUser({username: 'Joker'}).then(function(response) { | |
console.log(response.config); | |
}, function(response) { | |
console.log(response.status); | |
}); | |
}]) | |
.config(['$httpProvider', function($httpProvider) { | |
$httpProvider.interceptors.push(function() { | |
return { | |
'request': function(config) { | |
var url = config.url.split("/"); | |
var params = config.params; | |
console.log("ENDPOINT /" + url[url.length-1]); | |
if(params) { | |
console.log("PARAMS ", params); | |
} | |
return config; | |
} | |
} | |
}) | |
}]); | |
</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", []) | |
.service("ApiService", ['$http', function ($http) { | |
// 'https://jsonplaceholder.typicode.com/users' | |
var service = {}; | |
service.postUser = function(user) { | |
return $http.post('https://jsonplaceholder.typicode.com/usexxrs', user); | |
}; | |
return service; | |
}]) | |
.controller("myCtrl", ['ApiService', function (ApiService) { | |
ApiService.postUser({username: 'Joker'}).then(function(response) { | |
console.log(response.config); | |
}, function(response) { | |
console.log(response.status); | |
}); | |
}]) | |
.config(['$httpProvider', function($httpProvider) { | |
$httpProvider.interceptors.push(function() { | |
return { | |
'request': function(config) { | |
var url = config.url.split("/"); | |
var params = config.params; | |
console.log("ENDPOINT /" + url[url.length-1]); | |
if(params) { | |
console.log("PARAMS ", params); | |
} | |
return config; | |
} | |
} | |
}) | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment