|
37 | 37 | * the data object (useful for non-GET operations).
|
38 | 38 | *
|
39 | 39 | * @param {Object.<Object>=} actions Hash with declaration of custom action that should extend the
|
40 |
| - * default set of resource actions. The declaration should be created in the following format: |
| 40 | + * default set of resource actions. The declaration should be created in the format of {@link |
| 41 | + * ng.$http#Parameters $http.config}: |
41 | 42 | *
|
42 |
| - * {action1: {method:?, params:?, isArray:?, headers:?}, |
43 |
| - * action2: {method:?, params:?, isArray:?, headers:?}, |
| 43 | + * {action1: {method:?, params:?, isArray:?, headers:?, ...}, |
| 44 | + * action2: {method:?, params:?, isArray:?, headers:?, ...}, |
44 | 45 | * ...}
|
45 | 46 | *
|
46 | 47 | * Where:
|
47 | 48 | *
|
48 |
| - * - `action` – {string} – The name of action. This name becomes the name of the method on your |
| 49 | + * - **`action`** – {string} – The name of action. This name becomes the name of the method on your |
49 | 50 | * resource object.
|
50 |
| - * - `method` – {string} – HTTP request method. Valid methods are: `GET`, `POST`, `PUT`, `DELETE`, |
51 |
| - * and `JSONP` |
52 |
| - * - `params` – {Object=} – Optional set of pre-bound parameters for this action. If any of the |
53 |
| - * parameter value is a function, it will be executed every time when a param value needs to be |
54 |
| - * obtained for a request (unless the param was overriden). |
55 |
| - * - isArray – {boolean=} – If true then the returned object for this action is an array, see |
| 51 | + * - **`method`** – {string} – HTTP request method. Valid methods are: `GET`, `POST`, `PUT`, `DELETE`, |
| 52 | + * and `JSONP`. |
| 53 | + * - **`params`** – {Object=} – Optional set of pre-bound parameters for this action. If any of the |
| 54 | + * parameter value is a function, it will be executed every time when a param value needs to be |
| 55 | + * obtained for a request (unless the param was overriden). |
| 56 | + * - **`isArray`** – {boolean=} – If true then the returned object for this action is an array, see |
56 | 57 | * `returns` section.
|
57 |
| - * - `headers` – {Object=} – Optional HTTP headers to send |
| 58 | + * - **`transformRequest`** – `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` – |
| 59 | + * transform function or an array of such functions. The transform function takes the http |
| 60 | + * request body and headers and returns its transformed (typically serialized) version. |
| 61 | + * - **`transformResponse`** – `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` – |
| 62 | + * transform function or an array of such functions. The transform function takes the http |
| 63 | + * response body and headers and returns its transformed (typically deserialized) version. |
| 64 | + * - **`cache`** – `{boolean|Cache}` – If true, a default $http cache will be used to cache the |
| 65 | + * GET request, otherwise if a cache instance built with |
| 66 | + * {@link ng.$cacheFactory $cacheFactory}, this cache will be used for |
| 67 | + * caching. |
| 68 | + * - **`timeout`** – `{number}` – timeout in milliseconds. |
| 69 | + * - **`withCredentials`** - `{boolean}` - whether to to set the `withCredentials` flag on the |
| 70 | + * XHR object. See {@link https://developer.mozilla.org/en/http_access_control#section_5 |
| 71 | + * requests with credentials} for more information. |
| 72 | + * - **`responseType`** - `{string}` - see {@link |
| 73 | + * https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType requestType}. |
58 | 74 | *
|
59 | 75 | * @returns {Object} A resource "class" object with methods for the default set of resource actions
|
60 | 76 | * optionally extended with custom `actions`. The default set contains these actions:
|
@@ -374,12 +390,17 @@ angular.module('ngResource', ['ng']).
|
374 | 390 | }
|
375 | 391 |
|
376 | 392 | var value = this instanceof Resource ? this : (action.isArray ? [] : new Resource(data));
|
377 |
| - $http({ |
378 |
| - method: action.method, |
379 |
| - url: route.url(extend({}, extractParams(data, action.params || {}), params)), |
380 |
| - data: data, |
381 |
| - headers: extend({}, action.headers || {}) |
382 |
| - }).then(function(response) { |
| 393 | + var httpConfig = {}; |
| 394 | + |
| 395 | + forEach(action, function(value, key) { |
| 396 | + if (key != 'params' && key != 'isArray' ) { |
| 397 | + httpConfig[key] = copy(value); |
| 398 | + } |
| 399 | + }); |
| 400 | + httpConfig.data = data; |
| 401 | + httpConfig.url = route.url(extend({}, extractParams(data, action.params || {}), params)) |
| 402 | + |
| 403 | + $http(httpConfig).then(function(response) { |
383 | 404 | var data = response.data;
|
384 | 405 |
|
385 | 406 | if (data) {
|
|
0 commit comments