You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+58-35Lines changed: 58 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -143,10 +143,12 @@ To use the `SpringDataRestAdapter` object you need to include the `angular-sprin
143
143
var myApp =angular.module("myApplication", ["ngResource", "spring-data-rest"]);
144
144
```
145
145
146
-
Now you are able use the `SpringDataRestAdapter` object and process a given response:
146
+
Now you are able use the `SpringDataRestAdapter` object and process a given response and you will get a promise back which resolves with the processes response:
147
147
148
148
```javascript
149
-
var processedResponse =SpringDataRestAdapter.process(response);
Please read on on how to use the `_resources` method and the `_embeddedItems` property to ease the handling of resources and embedded items.
@@ -168,13 +170,14 @@ var response = {
168
170
}
169
171
...
170
172
}
171
-
var processedResponse =SpringDataRestAdapter.process(response);
172
173
```
173
174
174
-
Then the `SpringDataRestAdapter` will add the `_resources` method to the same level such that you can call it the following way:
175
+
Then the `SpringDataRestAdapter` will add the `_resources` method to the same level such that you can call it the following way (inside the `then` function of the promise):
This `_resources` method is added recursively to all the properties of the JSON response object where a `_links` property exists.
@@ -186,14 +189,16 @@ The `_resources` method takes the following four parameters:
186
189
*`linkName`: the name of the link's `href` you want to call with the underlying *Angular*`$resource` function. You can also pass in a resource object with parameters in the following way:
This will call *Angular*`$resource` method by default (this is [exchangeable](#exchange-the-underlying-angular-resource-function)) with the `href` of the `self` resource and will add the parameters `size` and `sort` as query string to the URL. If the resource object parameters and the `paramDefaults` parameters are set, then these two objects are merged such that the resource object parameters appear first in the new object and the `paramDefaults` parameters last.
@@ -222,12 +227,13 @@ var response = {
222
227
}
223
228
...
224
229
}
225
-
var processedResponse =SpringDataRestAdapter.process(response);
226
230
```
227
231
Then the following call to the `_resources` method without any parameter will return an array of all available resource objects.
228
232
229
233
```javascript
230
-
var availableResources =processedResponse._resources();
var availableResources =processedResponse._resources();
236
+
});
231
237
```
232
238
233
239
The above call will result in the following return value:
@@ -255,13 +261,14 @@ This functionality is useful if you want to first check all available resources
255
261
This example refers to the JSON response in the [Overview](#overview). If you want to get the parent category of a category you would call the `_resources` method the following way:
256
262
257
263
```javascript
258
-
var processedResponse =SpringDataRestAdapter.process(response);
259
-
var parentCategoryResource =processedResponse._embeddedItems[0]._resources("parentCategory");
@@ -294,11 +301,12 @@ The `_embeddedItems` property is just a convention property created by the `Spri
294
301
This example refers to the JSON response in the [Overview](#overview). If you want to iterate over all categories in the response you would do it in the following way:
295
302
296
303
```javascript
297
-
var processedResponse =SpringDataRestAdapter.process(response);
Now the response of the `anotherLink` will be processed the same way as the main response was processed. But *be aware* when setting the recursive flag to true, because when your reponses of the links contain the same link name again, then it will end up in a infinite loop.
346
353
347
-
348
354
It will not fetch the `self` link as this would make no sense because the data is already in the response. The `self` key is also configurable. Read more [here](#configuration-of-the-springdatarestadapter).
349
355
350
356
#### Fetch multiple or all links
351
357
352
358
If you want to fetch multiple links then you are able to add an array of strings with the given link names:
353
359
354
360
```javascript
355
-
var processedResponse =SpringDataRestAdapter.process(response, ['anotherLink', 'testLink']);
Please read more [here](#configuration-of-the-springdatarestadapter) on how to configure the `fetchAllLinkNamesKey`.
@@ -395,7 +404,7 @@ The parameters for the fetch method are the following:
395
404
396
405
### How to use `SpringDataRestAdapter` with promises
397
406
398
-
The `SpringDataRestAdapter` is also able to process promises instead of data objects. The data object which is passed to the specified promise when it is resolved needs to be in the following format:
407
+
The `SpringDataRestAdapter` is also able to process promises instead of data objects. The data object which is passed to the specified promise when it is resolved needs to be in the following formats:
399
408
400
409
```javascript
401
410
{
@@ -414,17 +423,31 @@ The `SpringDataRestAdapter` is also able to process promises instead of data obj
The `data` property of the promise object is the JSON response of the back end. To process such a promise you need to call the `SpringDataRestAdapter` like in the following example:
443
+
The `data` property of the second format of the promise object is the JSON response of the back end. To process such a promise you need to call the `SpringDataRestAdapter` like in the following example:
// you can now use the processedResponse as any other processed response from the SpringDataRestAdapter
423
448
};
424
449
```
425
450
426
-
The only change between the `SpringDataRestAdapter.processWithPromise` and the `SpringDataRestAdapter.process` methods is the changed type of the data object. All other parameters are the same.
427
-
428
451
You can also right away use the promise support with the `Angular``$http.get()` method like in the following example:
0 commit comments