Is there a way to set my API host as the default host, e.g. http://example.com/v1, so that I don't have to specify the full url in every $http or $resource request? That way I can use relative URLs.
I looked for something like that and came up empty. In the end I really didn't want that because it would prevent me from hitting APIs other than the one specified host. What I ended up doing is I created a constant with the API url which I would then inject in any service that needs it. Something like this:
angular.module('admin').constant('ApiUrl', 'http://example.com/v1');
which could go on your module file, and then on a service:
(function () {
'use strict';
angular
.module('admin')
.factory('SampleFactory', SampleFactory);
SampleFactory.$inject = ['$resource', 'ApiUrl'];
function SampleFactory($resource, ApiUrl) {
var resource = $resource(ApiUrl + 'cohort/:id', {}, { update: { method: 'PUT' } });
return resource;
}
})();