Skip to content

Instantly share code, notes, and snippets.

@joshdmiller
Created March 15, 2013 20:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshdmiller/5172882 to your computer and use it in GitHub Desktop.
Save joshdmiller/5172882 to your computer and use it in GitHub Desktop.
A starting point for an $http-backed RESTful model in AngularJS.
.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