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
The client provides a set of methods to manipulate resources and relationships.
50
+
The client provides a set of methods to deal with resources and relationships.
40
51
- Fetching
41
52
-[fetchCollection](https://pub.dartlang.org/documentation/json_api/latest/json_api/JsonApiClient/fetchCollection.html) - resource collection, either primary or related
42
53
-[fetchResource](https://pub.dartlang.org/documentation/json_api/latest/json_api/JsonApiClient/fetchResource.html) - a single resource, either primary or related
@@ -54,92 +65,60 @@ The client provides a set of methods to manipulate resources and relationships.
54
65
-[addToMany](https://pub.dartlang.org/documentation/json_api/latest/json_api/JsonApiClient/addToMany.html) - adds the given identifiers to the existing to-many relationship
55
66
56
67
These methods accept the target URI and the object to update (except for fetch and delete requests).
57
-
You can also pass an optional map of HTTP headers e.g. for authentication. The return value
58
-
is [Response](https://pub.dartlang.org/documentation/json_api/latest/json_api/Response-class.html) object bearing the
59
-
HTTP response status and headers and the JSON:API
60
-
document with the primary data according to the type of the request.
68
+
You can also pass an optional map of HTTP headers, e.g. for authentication. The return value
69
+
is a [Response] object.
61
70
62
-
Here's a collection fetching example:
71
+
You can get the status of the [Response] from either [Response.status] or one of the following properties:
72
+
-[Response.isSuccessful]
73
+
-[Response.isFailed]
74
+
-[Response.isAsync] (see [Asynchronous Processing])
63
75
64
-
```dart
65
-
import 'package:json_api/json_api.dart';
66
-
67
-
void main() async {
68
-
final client = JsonApiClient();
69
-
final companiesUri = Uri.parse('http://localhost:8080/companies');
70
-
final response = await client.fetchCollection(companiesUri);
71
-
72
-
print('Status: ${response.status}');
73
-
print('Headers: ${response.headers}');
74
-
75
-
print('The collection page size is ${response.data.collection.length}');
76
-
77
-
final resource = response.data.collection.first.toResource();
The Client always returns a [Response object](https://pub.dartlang.org/documentation/json_api/latest/json_api/Response-class.html)
91
-
which indicates either a successful, failed, or async (neither failed nor successful yet, see [here](https://jsonapi.org/recommendations/#asynchronous-processing)) operation.
92
-
You can determine which one you have by reading these properties:
the `Content-Location:` header used for asynchronous processing
104
-
105
-
### The Response Document
106
-
The most important part of the Response is the [document](https://pub.dartlang.org/documentation/json_api/latest/json_api/Response/document.html)
107
-
property which contains the JSON:API document sent by the server (if any). If the document has Primary Data, you
108
-
can use [data](https://pub.dartlang.org/documentation/json_api/latest/json_api/Response/data.html)
109
-
shortcut to access it directly. Like the Document, the Response is generalized by the expected Primary Data
110
-
which depends of the operation. The Document and the rest of the JSON:API object model are parts of [json_api_document](https://pub.dartlang.org/packages/json_api_document)
111
-
which is a separate package. Refer to that package for [complete API documentation](https://pub.dartlang.org/documentation/json_api_document/latest/).
112
-
This README only gives a brief overview.
113
-
114
-
#### Successful responses
115
-
Most of the times when the response is successful, you can read the [data](https://pub.dartlang.org/documentation/json_api/latest/json_api/Response/data.html)
116
-
property directly. It will be either a [primary resource](https://pub.dartlang.org/documentation/json_api_document/latest/json_api_document/ResourceData-class.html)
or a relationship: [to-one](https://pub.dartlang.org/documentation/json_api_document/latest/json_api_document/ToOne-class.html)
119
-
or [to-many](https://pub.dartlang.org/documentation/json_api_document/latest/json_api_document/ToMany-class.html).
120
-
The collection-like data may also contain [pagination links](https://pub.dartlang.org/documentation/json_api_document/latest/json_api_document/Pagination-class.html).
78
+
-[Response.location] holds the `Location` header used in creation requests
79
+
-[Response.contentLocation] holds the `Content-Location` header used for [Asynchronous Processing]
80
+
81
+
The most important part of the Response is the [Response.document] containing the JSON:API document sent by the server (if any).
82
+
If the document has the Primary Data, you can use [Response.data] shortcut to access it directly.
121
83
122
84
#### Included resources
123
-
If you requested related resources to be included in the response (see [Compound Documents](https://jsonapi.org/format/#document-compound-documents)) and the server fulfilled
124
-
your request, the [included](https://pub.dartlang.org/documentation/json_api_document/latest/json_api_document/PrimaryData/included.html) property will contain them.
85
+
If you requested related resources to be included in the response (see [Compound Documents]) and the server fulfilled
86
+
your request, the [PrimaryData.included] property will contain them.
125
87
126
88
#### Errors
127
-
For unsuccessful operations the [data](https://pub.dartlang.org/documentation/json_api/latest/json_api/Response/data.html)
128
-
property will be null. If the server decided to include the error details in the response, those can be found in the
0 commit comments