Skip to content

Instantly share code, notes, and snippets.

@byronferguson
Created September 28, 2015 20:32
Show Gist options
  • Save byronferguson/8e4a43d9d5b100fc96b4 to your computer and use it in GitHub Desktop.
Save byronferguson/8e4a43d9d5b100fc96b4 to your computer and use it in GitHub Desktop.
factory to generate RESTful API interface for DI into controllers
angular.module('cc.services').factory('studentFactory', function($http) {
var urlBase = '/api/v1/index.cfm/students';
var resourceFactory = {};
resourceFactory.getList = function() {
return $http.get(urlBase);
};
resourceFactory.getStudentByID = function(studentID) {
return $http.get(urlBase + '/' + studentID);
};
resourceFactory.getStudentByEmail = function(studentEmail) {
return $http.get(urlBase + '/' + studentEmail);
};
resourceFactory.getReport = function(studentID) {
return $http.get(urlBase + '/' + studentID + '/report');
};
resourceFactory.getDetails = function(studentID) {
return $http.get(urlBase + '/' + studentID + '/details');
};
resourceFactory.getClusterRanks = function(studentID) {
return $http.get(urlBase + '/' + studentID + '/clusterRanks');
};
resourceFactory.createStudent = function(firstName, lastName, email) {
return $http.post(urlBase, {firstName: firstName, lastName: lastName, email: email});
}
return resourceFactory;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment