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.
40
40
- Fetching
41
-
-`fetchCollection` - resource collection, either primary or related
42
-
-`fetchResource` - a single resource, either primary or related
43
-
-`fetchRelationship` - a generic relationship (either to-one, to-many or even incomplete)
44
-
-`fetchToOne` - a to-one relationship
45
-
-`fetchToMany` - a to-many relationship
41
+
-[fetchCollection](https://pub.dartlang.org/documentation/json_api/latest/json_api/JsonApiClient/fetchCollection.html) - resource collection, either primary or related
42
+
-[fetchResource](https://pub.dartlang.org/documentation/json_api/latest/json_api/JsonApiClient/fetchResource.html) - a single resource, either primary or related
43
+
-[fetchRelationship](https://pub.dartlang.org/documentation/json_api/latest/json_api/JsonApiClient/fetchRelationship.html) - a generic relationship (either to-one, to-many or even incomplete)
44
+
-[fetchToOne](https://pub.dartlang.org/documentation/json_api/latest/json_api/JsonApiClient/fetchToOne.html) - a to-one relationship
45
+
-[fetchToMany](https://pub.dartlang.org/documentation/json_api/latest/json_api/JsonApiClient/fetchToMany.html) - a to-many relationship
46
46
- Manipulating resources
47
-
-`createResource` - creates a new primary resource
48
-
-`updateResource` - updates the existing resource by its type and id
49
-
-`deleteResource` - deletes the existing resource
47
+
-[createResource](https://pub.dartlang.org/documentation/json_api/latest/json_api/JsonApiClient/createResource.html) - creates a new primary resource
48
+
-[updateResource](https://pub.dartlang.org/documentation/json_api/latest/json_api/JsonApiClient/updateResource.html) - updates the existing resource by its type and id
49
+
-[deleteResource](https://pub.dartlang.org/documentation/json_api/latest/json_api/JsonApiClient/deleteResource.html) - deletes the existing resource
50
50
- Manipulating relationships
51
-
-`replaceToOne` - replaces the existing to-one relationship with a new resource identifier
52
-
-`deleteToOne` - deletes the existing to-one relationship by setting the resource identifier to null
53
-
-`replaceToMany` - replaces the existing to-many relationship with the given set of resource identifiers
54
-
-`addToMany` - adds the given identifiers to the existing to-many relationship
51
+
-[replaceToOne](https://pub.dartlang.org/documentation/json_api/latest/json_api/JsonApiClient/replaceToOne.html) - replaces the existing to-one relationship with a new resource identifier
52
+
-[deleteToOne](https://pub.dartlang.org/documentation/json_api/latest/json_api/JsonApiClient/deleteToOne.html) - deletes the existing to-one relationship by setting the resource identifier to null
53
+
-[replaceToMany](https://pub.dartlang.org/documentation/json_api/latest/json_api/JsonApiClient/replaceToMany.html) - replaces the existing to-many relationship with the given set of resource identifiers
54
+
-[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
55
56
56
These methods accept the target URI and the object to update (except for fetch and delete requests).
57
57
You can also pass an optional map of HTTP headers e.g. for authentication. The return value
58
-
is `Response` object bearing the HTTP response status and headers and the JSON:API
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
59
60
document with the primary data according to the type of the request.
60
61
61
62
Here's a collection fetching example:
@@ -85,5 +86,60 @@ void main() async {
85
86
}
86
87
```
87
88
88
-
89
+
### The Response object
90
+
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 present 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).
121
+
122
+
#### 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.
125
+
126
+
#### 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