Created
March 15, 2013 20:27
-
-
Save joshdmiller/5172882 to your computer and use it in GitHub Desktop.
A starting point for an $http-backed RESTful model in AngularJS.
This file contains 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
.factory( 'UserService', [ '$http', function ( $http ) { | |
var url = '/api/users'; | |
/** | |
* This is the private API. | |
*/ | |
// get a list of users | |
function query () { | |
return $http.get( url ); | |
} | |
// get a user by id | |
function get ( id ) { | |
return $http.get( url+'/'+id, { params: { id: id } }); | |
} | |
// remove a user | |
function remove ( id ) { | |
return $http.delete( url+'/'+id ); | |
} | |
// create a user | |
function create ( user ) { | |
return $http.post( url, user ); | |
} | |
// update a user | |
function save ( user ) { | |
return $http.put( url+'/'+user.id, user ); | |
} | |
/** | |
* This is the public API. | |
*/ | |
return { | |
get: get | |
query: query, | |
remove: remove, | |
save: save, | |
create: create | |
} | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment