Working on a application that requires multiple components to be displayed on the same page that need data from the same api url.
As per example I have two components, one is a breadcrumb one is the actual data container and both of them will request the status of a component in order to display relevant data.
data factory
angular
.module('app')
.factory('data', function($http) {
this.getStatus = function() {
return $http.get('/api/status/');
}
return this;
});
controller 1
angular
.module('app')
.controller('breadcrumb', function(data, breadcrumbProcessor) {
var _self = this;
data
.getStatus()
.then(function(response) {
_self.activeBreadcrumb = breadcrumbProcessor(response.data);
});
});
controller 2
angular
.module('app')
.controller('form', function(data, formProcessor) {
var _self = this;
data
.getStatus()
.then(function(response) {
_self.activeForm = formProcessor(response.data);
});
});
The first component will be a breadcrumb that shows the stage of the process while the second component will be a page where you show a form depending on the stage. So I will call for both components the same api "GET:/api/stage/" which will case 2 requests to be made to the server.
Is it possible (and if so how would it look like) to make an interceptor or service that acts like a filter for the requests and merges them into a single request?