@@ -169,9 +169,9 @@ function shallowClearAndCopy(src, dst) {
169
169
* By default, transformResponse will contain one function that checks if the response looks
170
170
* like a JSON string and deserializes it using `angular.fromJson`. To prevent this behavior,
171
171
* set `transformResponse` to an empty array: `transformResponse: []`
172
- * - **`cache`** – `{boolean|Cache}` – If true, a default `$http` cache will be used to cache the
173
- * GET request, otherwise if a cache instance built with {@link ng.$cacheFactory $cacheFactory}
174
- * is supplied, this cache will be used for caching .
172
+ * - **`cache`** – `{boolean|Cache}` – A boolean value or object created with
173
+ * {@link ng.$cacheFactory ` $cacheFactory`} to enable or disable caching of the HTTP response.
174
+ * See { @link $http#caching $http Caching} for more information .
175
175
* - **`timeout`** – `{number}` – Timeout in milliseconds.<br />
176
176
* **Note:** In contrast to {@link ng.$http#usage $http.config}, {@link ng.$q promises} are
177
177
* **not** supported in `$resource`, because the same value would be used for multiple requests.
@@ -180,13 +180,13 @@ function shallowClearAndCopy(src, dst) {
180
180
* cancelled (if not already completed) by calling `$cancelRequest()` on the call's return
181
181
* value. Calling `$cancelRequest()` for a non-cancellable or an already completed/cancelled
182
182
* request will have no effect.
183
- * - **`withCredentials`** - `{boolean}` - Whether to set the `withCredentials` flag on the
183
+ * - **`withCredentials`** – `{boolean}` – Whether to set the `withCredentials` flag on the
184
184
* XHR object. See
185
185
* [XMLHttpRequest.withCredentials](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials)
186
186
* for more information.
187
- * - **`responseType`** - `{string}` - See
187
+ * - **`responseType`** – `{string}` – See
188
188
* [XMLHttpRequest.responseType](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType).
189
- * - **`interceptor`** - `{Object=}` - The interceptor object has four optional methods -
189
+ * - **`interceptor`** – `{Object=}` – The interceptor object has four optional methods -
190
190
* `request`, `requestError`, `response`, and `responseError`. See
191
191
* {@link ng.$http#interceptors $http interceptors} for details. Note that
192
192
* `request`/`requestError` interceptors are applied before calling `$http`, thus before any
@@ -198,9 +198,8 @@ function shallowClearAndCopy(src, dst) {
198
198
* response interceptors. Make sure you return an appropriate value and not the `response`
199
199
* object passed as input. For example, the default `response` interceptor (which gets applied
200
200
* if you don't specify a custom one) returns `response.resource`.
201
- * - **`hasBody`** - `{boolean}` - Allows to specify if a request body should be included or not.
202
- * If not specified only POST, PUT and PATCH requests will have a body.
203
- *
201
+ * - **`hasBody`** – `{boolean}` – If true, then the request will have a body.
202
+ * If not specified, then only POST, PUT and PATCH requests will have a body. *
204
203
* @param {Object } options Hash with custom settings that should extend the
205
204
* default `$resourceProvider` behavior. The supported options are:
206
205
*
@@ -299,18 +298,18 @@ function shallowClearAndCopy(src, dst) {
299
298
*
300
299
* @example
301
300
*
302
- * ### Credit card resource
301
+ * ### Basic usage
303
302
*
304
303
```js
305
- // Define CreditCard class
306
- var CreditCard = $resource('/user /:userId/card /:cardId',
304
+ // Define a CreditCard class
305
+ var CreditCard = $resource('/users /:userId/cards /:cardId',
307
306
{userId: 123, cardId: '@id' }, {
308
307
charge: {method: 'POST', params: {charge: true}}
309
308
});
310
309
311
310
// We can retrieve a collection from the server
312
311
var cards = CreditCard.query();
313
- // GET: /user /123/card
312
+ // GET: /users /123/cards
314
313
// server returns: [{id: 456, number: '1234', name: 'Smith'}]
315
314
316
315
// Wait for the request to complete
@@ -323,23 +322,25 @@ function shallowClearAndCopy(src, dst) {
323
322
// Non-GET methods are mapped onto the instances
324
323
card.name = 'J. Smith';
325
324
card.$save();
326
- // POST: /user /123/card /456 {id: 456, number: '1234', name: 'J. Smith'}
325
+ // POST: /users /123/cards /456 {id: 456, number: '1234', name: 'J. Smith'}
327
326
// server returns: {id: 456, number: '1234', name: 'J. Smith'}
328
327
329
328
// Our custom method is mapped as well (since it uses POST)
330
329
card.$charge({amount: 9.99});
331
- // POST: /user /123/card /456?amount=9.99&charge=true {id: 456, number: '1234', name: 'J. Smith'}
330
+ // POST: /users /123/cards /456?amount=9.99&charge=true {id: 456, number: '1234', name: 'J. Smith'}
332
331
});
333
332
334
333
// We can create an instance as well
335
334
var newCard = new CreditCard({number: '0123'});
336
335
newCard.name = 'Mike Smith';
337
336
338
337
var savePromise = newCard.$save();
339
- // POST: /user /123/card {number: '0123', name: 'Mike Smith'}
338
+ // POST: /users /123/cards {number: '0123', name: 'Mike Smith'}
340
339
// server returns: {id: 789, number: '0123', name: 'Mike Smith'}
341
340
342
341
savePromise.then(function() {
342
+ // Once the promise is resolved, the created instance
343
+ // is populated with the data returned by the server
343
344
expect(newCard.id).toEqual(789);
344
345
});
345
346
```
@@ -352,14 +353,14 @@ function shallowClearAndCopy(src, dst) {
352
353
*
353
354
* @example
354
355
*
355
- * ### User resource
356
+ * ### Accessing the response
356
357
*
357
358
* When the data is returned from the server then the object is an instance of the resource type and
358
359
* all of the non-GET methods are available with `$` prefix. This allows you to easily support CRUD
359
360
* operations (create, read, update, delete) on server-side data.
360
361
*
361
362
```js
362
- var User = $resource('/user /:userId', {userId: '@id '});
363
+ var User = $resource('/users /:userId', {userId: '@id '});
363
364
User.get({userId: 123}).$promise.then(function(user) {
364
365
user.abc = true;
365
366
user.$save();
@@ -372,7 +373,7 @@ function shallowClearAndCopy(src, dst) {
372
373
* the above example and get access to HTTP headers as follows:
373
374
*
374
375
```js
375
- var User = $resource('/user /:userId', {userId: '@id '});
376
+ var User = $resource('/users /:userId', {userId: '@id '});
376
377
User.get({userId: 123}, function(user, getResponseHeaders) {
377
378
user.abc = true;
378
379
user.$save(function(user, putResponseHeaders) {
@@ -384,7 +385,7 @@ function shallowClearAndCopy(src, dst) {
384
385
*
385
386
* @example
386
387
*
387
- * ### Creating a custom 'PUT' request
388
+ * ### Creating custom actions
388
389
*
389
390
* In this example we create a custom method on our resource to make a PUT request:
390
391
*
@@ -429,7 +430,7 @@ function shallowClearAndCopy(src, dst) {
429
430
*
430
431
```js
431
432
// ...defining the `Hotel` resource...
432
- var Hotel = $resource('/api/hotel /:id', {id: '@id' }, {
433
+ var Hotel = $resource('/api/hotels /:id', {id: '@id' }, {
433
434
// Let's make the `query()` method cancellable
434
435
query: {method: 'get', isArray: true, cancellable: true}
435
436
});
@@ -444,7 +445,7 @@ function shallowClearAndCopy(src, dst) {
444
445
}
445
446
446
447
// Let's query for hotels in `destination`
447
- // (calls: /api/hotel ?location=<destination>)
448
+ // (calls: /api/hotels ?location=<destination>)
448
449
this.availableHotels = Hotel.query({location: destination});
449
450
};
450
451
```
0 commit comments