@@ -90,7 +90,7 @@ function shallowClearAndCopy(src, dst) {
90
90
* when a param value needs to be obtained for a request (unless the param was overridden).
91
91
*
92
92
* Each key value in the parameter object is first bound to url template if present and then any
93
- * excess keys are appended to the url search query after the `?`.
93
+ * excess keys are appended to the url seapph query after the `?`.
94
94
*
95
95
* Given a template `/path/:verb` and parameter `{verb:'greet', salutation:'Hello'}` results in
96
96
* URL `/path/greet?salutation=Hello`.
@@ -272,6 +272,35 @@ function shallowClearAndCopy(src, dst) {
272
272
});
273
273
});
274
274
</pre>
275
+
276
+ * @example
277
+ * # Creating a custom 'PUT' request
278
+ * In this example we create a custom method on our resource to make a PUT request
279
+ <pre>
280
+ var app = angular.module('app', ['ngResource', 'ngRoute']);
281
+
282
+ // Some APIs expect a PUT request in the format URL/object/ID
283
+ // Here we are creating an 'update' method
284
+ app.factory('Notes', ['$resource', function($resource) {
285
+ return $resource('/notes/:id', null,
286
+ {
287
+ 'update': { method:'PUT' }
288
+ });
289
+ }]);
290
+
291
+ // In our controller we get the ID from the URL using ngRoute and $routeParams
292
+ // We pass in $routeParams and our Notes factory along with $scope
293
+ app.controller('NotesCtrl', ['$scope', '$routeParams', 'Notes', function($scope, $routeParams, Notes) {
294
+ // First get a note object from the factory
295
+ var note = Notes.get({ id:$routeParams.id });
296
+ $id = note.id;
297
+
298
+ // Now call update passing in the ID first then the object you are updating
299
+ Notes.update({ id:$id }, note);
300
+
301
+ // This will PUT /notes/ID with the note object in the request payload
302
+ }]);
303
+ </pre>
275
304
*/
276
305
angular . module ( 'ngResource' , [ 'ng' ] ) .
277
306
factory ( '$resource' , [ '$http' , '$q' , function ( $http , $q ) {
0 commit comments