aboutsummaryrefslogtreecommitdiffstats
path: root/src/ngResource/resource.js
diff options
context:
space:
mode:
authorunclejustin2013-12-05 21:41:58 -0600
committerPete Bacon Darwin2013-12-17 12:20:25 +0000
commit3174f7333672c96613825976c883f79ad4d41016 (patch)
treed7e2dfbe23390464803430b0428acc194ab224aa /src/ngResource/resource.js
parent3c62e4244e6d3b8597e1fd9693d0eef2e6ddca7d (diff)
downloadangular.js-3174f7333672c96613825976c883f79ad4d41016.tar.bz2
docs($resource): add example for a custom PUT request
Closes #5302
Diffstat (limited to 'src/ngResource/resource.js')
-rw-r--r--src/ngResource/resource.js31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js
index 8e63c4e8..3172096f 100644
--- a/src/ngResource/resource.js
+++ b/src/ngResource/resource.js
@@ -90,7 +90,7 @@ function shallowClearAndCopy(src, dst) {
* when a param value needs to be obtained for a request (unless the param was overridden).
*
* Each key value in the parameter object is first bound to url template if present and then any
- * excess keys are appended to the url search query after the `?`.
+ * excess keys are appended to the url seapph query after the `?`.
*
* Given a template `/path/:verb` and parameter `{verb:'greet', salutation:'Hello'}` results in
* URL `/path/greet?salutation=Hello`.
@@ -272,6 +272,35 @@ function shallowClearAndCopy(src, dst) {
});
});
</pre>
+
+ * @example
+ * # Creating a custom 'PUT' request
+ * In this example we create a custom method on our resource to make a PUT request
+ <pre>
+ var app = angular.module('app', ['ngResource', 'ngRoute']);
+
+ // Some APIs expect a PUT request in the format URL/object/ID
+ // Here we are creating an 'update' method
+ app.factory('Notes', ['$resource', function($resource) {
+ return $resource('/notes/:id', null,
+ {
+ 'update': { method:'PUT' }
+ });
+ }]);
+
+ // In our controller we get the ID from the URL using ngRoute and $routeParams
+ // We pass in $routeParams and our Notes factory along with $scope
+ app.controller('NotesCtrl', ['$scope', '$routeParams', 'Notes', function($scope, $routeParams, Notes) {
+ // First get a note object from the factory
+ var note = Notes.get({ id:$routeParams.id });
+ $id = note.id;
+
+ // Now call update passing in the ID first then the object you are updating
+ Notes.update({ id:$id }, note);
+
+ // This will PUT /notes/ID with the note object in the request payload
+ }]);
+ </pre>
*/
angular.module('ngResource', ['ng']).
factory('$resource', ['$http', '$q', function($http, $q) {