angularjs-coreservice v1.0.0
angularjs-coreservice
A base (model) class for services using Angular's Resource module
Installation
Install via Bower
bower install --save angularjs-coreserviceInstall via NPM
npm install --save-dev angularjs-coreserviceAdd the ApiHostname as a constant to your AngularJS Application.
The Coreserver depends on this constant.
angular.module('MyApplication').constant('ApiHostname', 'http://localhost\\:9000/api');Usage
find()
This call is needed when your API result is an object
Parameters:
queryobject|callback Enter the query string or recognizes this as successCallback when callback is givensuccessCallbackcallback This callback is called after data requested ended up with a HTTP 20xerrorCallbackcallback This callback is called after data requested ended up with another HTTP than 20x
Returns
$resource object
Find with object (Possible REST Example: GET http://url.com/app-variant/1.json?status=active)
AppVariants.find({id: 1, status: 'active'}) Find with object, successCallback
AppVariants.find({id: 1, status: 'active'}, function() { alert('done'); });Find without object and successCallback (Possible REST Example: GET http://url.com/app-variant.json)
AppVariants.find(function() { alert('done'); });findAll()
This call is needed when your API result is an array
Parameters:
queryobject|callback Enter the query string or recognizes this as successCallback when callback is givensuccessCallbackcallback This callback is called after data requested ended up with a HTTP 20xerrorCallbackcallback This callback is called after data requested ended up with another HTTP than 20x
Returns
$resource object
FindAll with object (Possible REST Example: GET http://url.com/app-variant.json?query=google)
AppVariants.findAll({query: 'google'}) Find with object, successCallback
AppVariants.findAll({query: 'google'}, function() { alert('done'); });Find without object and successCallback (Possible REST Example: GET http://url.com/app-variant.json)
AppVariants.findAll(function() { alert('done'); });findById()
This call is to do a quicker find call, when you only have an ID to GET
Parameters:
idstring The identifier to requestsuccessCallbackcallback This callback is called after data requested ended up with a HTTP 20xerrorCallbackcallback This callback is called after data requested ended up with another HTTP than 20x
Returns
$resource object
Find by ID without successCallback (Possible REST Example: GET http://url.com/app-variant/1.json)
AppVariants.findById(1)Find by ID with successCallback (Possible REST Example: GET http://url.com/app-variant/1.json)
AppVariants.findById(1, function() { alert('done'); });remove()
Do a DELETE call
Parameters:
querystring|object|callback Enter the query string or recognizes this as successCallback when callback is givensuccessCallbackcallback This callback is called after data requested ended up with a HTTP 20xerrorCallbackcallback This callback is called after data requested ended up with another HTTP than 20x
Returns
$resource object
Delete by ID (Possible REST Example: DELETE http://url.com/app-variant/1.json)
AppVariants.remove(1)Delete by ID with the callbacks (Possible REST Example: DELETE http://url.com/app-variant/1.json)
AppVariants.remove(1, function() { alert('done'); }, function() { alert('error') });Delete by object with the callbacks (Possible REST Example: DELETE http://url.com/app-variant.json?status=active)
AppVariants.remove({status: 'active'}, function() { alert('done'); }, function() { alert('error') });Delete all with the callbacks (Possible REST Example: DELETE http://url.com/app-variant.json)
AppVariants.remove(function() { alert('done'); }, function() { alert('error') });delete()
Alias for remove()
create()
Do a POST call
Parameters:
queryobject Enter the query string with data you want to savesuccessCallbackcallback This callback is called after data requested ended up with a HTTP 20xerrorCallbackcallback This callback is called after data requested ended up with another HTTP than 20x
Returns
$resource object
Example request:
[POST] http://url.com/app-variant.json
[REQUEST BODY - application/json]
{
name: 'Patrick',
likes: 'github'
}Post an object to the server
AppVariants.create({name: 'Patrick', likes: 'github'})Post an object to the server with callbacks
AppVariants.create({name: 'Patrick', likes: 'github'}, function() { alert('done') }, function() { alert('error') })update()
Do a PUT call
Parameters:
queryobject Enter the query string with data you want to savesuccessCallbackcallback This callback is called after data requested ended up with a HTTP 20xerrorCallbackcallback This callback is called after data requested ended up with another HTTP than 20x
Returns
$resource object
Example request:
[PUT] http://url.com/app-variant/1.json
[REQUEST BODY - application/json]
{
name: 'Patrick',
likes: 'github'
}Post an object to the server
AppVariants.update({id: 1, name: 'Patrick', likes: 'github'})Post an object to the server with callbacks
AppVariants.update({id: 1, name: 'Patrick', likes: 'github'}, function() { alert('done') }, function() { alert('error') })save()
Alias for create() and update(). If the given query object has an ID key it will to the update() call, otherwise it will do a create() call
Parameters:
queryobject Enter the query string with data you want to savesuccessCallbackcallback This callback is called after data requested ended up with a HTTP 20xerrorCallbackcallback This callback is called after data requested ended up with another HTTP than 20x
10 years ago