Created
October 6, 2017 10:44
-
-
Save gmittica/a15e53163055088571fe11e7a74745d9 to your computer and use it in GitHub Desktop.
JS Bin // source http://jsbin.com/bisugav
This file contains hidden or 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.defaults.headers.post['X-Return-Obj'] = "true"; | |
| }]) | |
| .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/users'); | |
| }; | |
| service.postUser = function(user) { | |
| return $http.post('https://jsonplaceholder.typicode.com/users', user); | |
| }; | |
| return service; | |
| }]) | |
| .controller("myCtrl", ['ApiService', function (ApiService) { | |
| ApiService.postUser({username: 'Joker'}); | |
| ApiService.getUsers(); | |
| }]) | |
| .config(['$httpProvider', function($httpProvider) { | |
| $httpProvider.interceptors.push(function() { | |
| return { | |
| 'request': function(config) { | |
| var url = config.url.split("/"); | |
| var params = config.params; | |
| console.log(config.method + " /" + url[url.length-1]); | |
| if(params) { | |
| console.log("PARAMS ", params); | |
| } | |
| console.log("HEADERS", config.headers); | |
| return config; | |
| } | |
| } | |
| }) | |
| }]); | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">angular.module("myApp", []) | |
| .config(['$httpProvider', function($httpProvider) { | |
| $httpProvider.defaults.headers.post['X-Return-Obj'] = "true"; | |
| }]) | |
| .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/users'); | |
| }; | |
| service.postUser = function(user) { | |
| return $http.post('https://jsonplaceholder.typicode.com/users', user); | |
| }; | |
| return service; | |
| }]) | |
| .controller("myCtrl", ['ApiService', function (ApiService) { | |
| ApiService.postUser({username: 'Joker'}); | |
| ApiService.getUsers(); | |
| }]) | |
| .config(['$httpProvider', function($httpProvider) { | |
| $httpProvider.interceptors.push(function() { | |
| return { | |
| 'request': function(config) { | |
| var url = config.url.split("/"); | |
| var params = config.params; | |
| console.log(config.method + " /" + url[url.length-1]); | |
| if(params) { | |
| console.log("PARAMS ", params); | |
| } | |
| console.log("HEADERS", config.headers); | |
| return config; | |
| } | |
| } | |
| }) | |
| }]); | |
| </script></body> | |
| </html> |
This file contains hidden or 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.defaults.headers.post['X-Return-Obj'] = "true"; | |
| }]) | |
| .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/users'); | |
| }; | |
| service.postUser = function(user) { | |
| return $http.post('https://jsonplaceholder.typicode.com/users', user); | |
| }; | |
| return service; | |
| }]) | |
| .controller("myCtrl", ['ApiService', function (ApiService) { | |
| ApiService.postUser({username: 'Joker'}); | |
| ApiService.getUsers(); | |
| }]) | |
| .config(['$httpProvider', function($httpProvider) { | |
| $httpProvider.interceptors.push(function() { | |
| return { | |
| 'request': function(config) { | |
| var url = config.url.split("/"); | |
| var params = config.params; | |
| console.log(config.method + " /" + url[url.length-1]); | |
| if(params) { | |
| console.log("PARAMS ", params); | |
| } | |
| console.log("HEADERS", config.headers); | |
| return config; | |
| } | |
| } | |
| }) | |
| }]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment