I try to keep my URLs close to where they are needed. Therefore, if I have a service, I would keep the base url; for example: this.rootUrl = '/api/v1/';
This allows me to have additional contextual methods that โextendโ the URL.
For example:
this.getBaseUrl = function(client_id, project_id) { return this.rootUrl + 'clients/' + client_id + '/projects/' + project_id + '/'; };
What can I use as follows:
this.createActivity = function(client_id, project_id, activity_name, callback) { $http.post(this.getBaseUrl(client_id, project_id) + 'activities', {activity: {name: activity_name}}) .success(callback) .error(this.handlerError); };
or how it is (within the same service):
this.closeActivity = function(activity_id, callback){ $http.get(this.rootUrl + 'close_activity/' + activity_id) .success(callback) .error(this.handlerError); };
-harold
haroldcampbell
source share