@@ -32,14 +32,12 @@ class RoutingClient {
32
32
List <Identifier > identifiers, {
33
33
Map <String , Object ?> meta = const {},
34
34
Map <String , List <String >> headers = const {},
35
- }) async {
36
- final response = await send (
37
- _baseUri.relationship (type, id, relationship),
38
- Request .post (
39
- OutboundDataDocument .many (ToMany (identifiers)..meta.addAll (meta)))
40
- ..headers.addAll (headers));
41
- return RelationshipUpdated .many (response.httpResponse, response.document);
42
- }
35
+ }) async =>
36
+ RelationshipUpdated .many (await send (
37
+ _baseUri.relationship (type, id, relationship),
38
+ Request .post (
39
+ OutboundDataDocument .many (ToMany (identifiers)..meta.addAll (meta)))
40
+ ..headers.addAll (headers)));
43
41
44
42
/// Creates a new resource with the given [type] and [id] on the server.
45
43
///
@@ -61,21 +59,19 @@ class RoutingClient {
61
59
Map <String , Object ?> documentMeta = const {},
62
60
Map <String , List <String >> headers = const {},
63
61
Iterable <QueryEncodable > query = const [],
64
- }) async {
65
- final response = await send (
66
- _baseUri.collection (type),
67
- Request .post (OutboundDataDocument .resource (Resource (type, id)
68
- ..attributes.addAll (attributes)
69
- ..relationships.addAll ({
70
- ...one.map ((key, value) => MapEntry (key, ToOne (value))),
71
- ...many.map ((key, value) => MapEntry (key, ToMany (value))),
72
- })
73
- ..meta.addAll (meta))
74
- ..meta.addAll (documentMeta))
75
- ..headers.addAll (headers)
76
- ..query.mergeAll (query));
77
- return ResourceUpdated (response.httpResponse, response.document);
78
- }
62
+ }) async =>
63
+ ResourceUpdated (await send (
64
+ _baseUri.collection (type),
65
+ Request .post (OutboundDataDocument .resource (Resource (type, id)
66
+ ..attributes.addAll (attributes)
67
+ ..relationships.addAll ({
68
+ ...one.map ((key, value) => MapEntry (key, ToOne (value))),
69
+ ...many.map ((key, value) => MapEntry (key, ToMany (value))),
70
+ })
71
+ ..meta.addAll (meta))
72
+ ..meta.addAll (documentMeta))
73
+ ..headers.addAll (headers)
74
+ ..query.mergeAll (query)));
79
75
80
76
/// Creates a new resource in the collection of type [type] .
81
77
/// The server is responsible for assigning the resource id.
@@ -99,24 +95,20 @@ class RoutingClient {
99
95
Map <String , Object ?> documentMeta = const {},
100
96
Map <String , List <String >> headers = const {},
101
97
Iterable <QueryEncodable > query = const [],
102
- }) async {
103
- final response = await send (
104
- _baseUri.collection (type),
105
- Request .post (
106
- OutboundDataDocument .newResource (NewResource (type, lid: lid)
107
- ..attributes.addAll (attributes)
108
- ..relationships.addAll ({
109
- ...one.map ((key, value) => MapEntry (key, NewToOne (value))),
110
- ...many.map ((key, value) => MapEntry (key, NewToMany (value))),
111
- })
112
- ..meta.addAll (meta))
113
- ..meta.addAll (documentMeta))
114
- ..headers.addAll (headers)
115
- ..query.mergeAll (query));
116
-
117
- return ResourceCreated (
118
- response.httpResponse, response.document ?? (throw FormatException ()));
119
- }
98
+ }) async =>
99
+ ResourceCreated (await send (
100
+ _baseUri.collection (type),
101
+ Request .post (
102
+ OutboundDataDocument .newResource (NewResource (type, lid: lid)
103
+ ..attributes.addAll (attributes)
104
+ ..relationships.addAll ({
105
+ ...one.map ((key, value) => MapEntry (key, NewToOne (value))),
106
+ ...many.map ((key, value) => MapEntry (key, NewToMany (value))),
107
+ })
108
+ ..meta.addAll (meta))
109
+ ..meta.addAll (documentMeta))
110
+ ..headers.addAll (headers)
111
+ ..query.mergeAll (query)));
120
112
121
113
/// Deletes the [identifiers] from the to-many relationship
122
114
/// identified by [type] , [id] , [relationship] .
@@ -131,15 +123,12 @@ class RoutingClient {
131
123
List <Identifier > identifiers, {
132
124
Map <String , Object ?> meta = const {},
133
125
Map <String , List <String >> headers = const {},
134
- }) async {
135
- final response = await send (
136
- _baseUri.relationship (type, id, relationship),
137
- Request .delete (
138
- OutboundDataDocument .many (ToMany (identifiers)..meta.addAll (meta)))
139
- ..headers.addAll (headers));
140
-
141
- return RelationshipUpdated .many (response.httpResponse, response.document);
142
- }
126
+ }) async =>
127
+ RelationshipUpdated .many (await send (
128
+ _baseUri.relationship (type, id, relationship),
129
+ Request .delete (
130
+ OutboundDataDocument .many (ToMany (identifiers)..meta.addAll (meta)))
131
+ ..headers.addAll (headers)));
143
132
144
133
/// Fetches the primary collection of type [type] .
145
134
///
@@ -150,15 +139,12 @@ class RoutingClient {
150
139
String type, {
151
140
Map <String , List <String >> headers = const {},
152
141
Iterable <QueryEncodable > query = const [],
153
- }) async {
154
- final response = await send (
155
- _baseUri.collection (type),
156
- Request .get ()
157
- ..headers.addAll (headers)
158
- ..query.mergeAll (query));
159
- return CollectionFetched (
160
- response.httpResponse, response.document ?? (throw FormatException ()));
161
- }
142
+ }) async =>
143
+ CollectionFetched (await send (
144
+ _baseUri.collection (type),
145
+ Request .get ()
146
+ ..headers.addAll (headers)
147
+ ..query.mergeAll (query)));
162
148
163
149
/// Fetches the related resource collection
164
150
/// identified by [type] , [id] , [relationship] .
@@ -172,15 +158,12 @@ class RoutingClient {
172
158
String relationship, {
173
159
Map <String , List <String >> headers = const {},
174
160
Iterable <QueryEncodable > query = const [],
175
- }) async {
176
- final response = await send (
177
- _baseUri.related (type, id, relationship),
178
- Request .get ()
179
- ..headers.addAll (headers)
180
- ..query.mergeAll (query));
181
- return CollectionFetched (
182
- response.httpResponse, response.document ?? (throw FormatException ()));
183
- }
161
+ }) async =>
162
+ CollectionFetched (await send (
163
+ _baseUri.related (type, id, relationship),
164
+ Request .get ()
165
+ ..headers.addAll (headers)
166
+ ..query.mergeAll (query)));
184
167
185
168
/// Fetches the to-one relationship
186
169
/// identified by [type] , [id] , [relationship] .
@@ -194,15 +177,12 @@ class RoutingClient {
194
177
String relationship, {
195
178
Map <String , List <String >> headers = const {},
196
179
Iterable <QueryEncodable > query = const [],
197
- }) async {
198
- final response = await send (
199
- _baseUri.relationship (type, id, relationship),
200
- Request .get ()
201
- ..headers.addAll (headers)
202
- ..query.mergeAll (query));
203
- return RelationshipFetched .one (
204
- response.httpResponse, response.document ?? (throw FormatException ()));
205
- }
180
+ }) async =>
181
+ RelationshipFetched .one (await send (
182
+ _baseUri.relationship (type, id, relationship),
183
+ Request .get ()
184
+ ..headers.addAll (headers)
185
+ ..query.mergeAll (query)));
206
186
207
187
/// Fetches the to-many relationship
208
188
/// identified by [type] , [id] , [relationship] .
@@ -216,15 +196,12 @@ class RoutingClient {
216
196
String relationship, {
217
197
Map <String , List <String >> headers = const {},
218
198
Iterable <QueryEncodable > query = const [],
219
- }) async {
220
- final response = await send (
221
- _baseUri.relationship (type, id, relationship),
222
- Request .get ()
223
- ..headers.addAll (headers)
224
- ..query.mergeAll (query));
225
- return RelationshipFetched .many (
226
- response.httpResponse, response.document ?? (throw FormatException ()));
227
- }
199
+ }) async =>
200
+ RelationshipFetched .many (await send (
201
+ _baseUri.relationship (type, id, relationship),
202
+ Request .get ()
203
+ ..headers.addAll (headers)
204
+ ..query.mergeAll (query)));
228
205
229
206
/// Fetches the related resource
230
207
/// identified by [type] , [id] , [relationship] .
@@ -238,15 +215,12 @@ class RoutingClient {
238
215
String relationship, {
239
216
Map <String , List <String >> headers = const {},
240
217
Iterable <QueryEncodable > query = const [],
241
- }) async {
242
- final response = await send (
243
- _baseUri.related (type, id, relationship),
244
- Request .get ()
245
- ..headers.addAll (headers)
246
- ..query.mergeAll (query));
247
- return RelatedResourceFetched (
248
- response.httpResponse, response.document ?? (throw FormatException ()));
249
- }
218
+ }) async =>
219
+ RelatedResourceFetched (await send (
220
+ _baseUri.related (type, id, relationship),
221
+ Request .get ()
222
+ ..headers.addAll (headers)
223
+ ..query.mergeAll (query)));
250
224
251
225
/// Fetches the resource identified by [type] and [id] .
252
226
///
@@ -258,16 +232,12 @@ class RoutingClient {
258
232
String id, {
259
233
Map <String , List <String >> headers = const {},
260
234
Iterable <QueryEncodable > query = const [],
261
- }) async {
262
- final response = await send (
263
- _baseUri.resource (type, id),
264
- Request .get ()
265
- ..headers.addAll (headers)
266
- ..query.mergeAll (query));
267
-
268
- return ResourceFetched (
269
- response.httpResponse, response.document ?? (throw FormatException ()));
270
- }
235
+ }) async =>
236
+ ResourceFetched (await send (
237
+ _baseUri.resource (type, id),
238
+ Request .get ()
239
+ ..headers.addAll (headers)
240
+ ..query.mergeAll (query)));
271
241
272
242
/// Updates the resource identified by [type] and [id] .
273
243
///
@@ -289,21 +259,19 @@ class RoutingClient {
289
259
Map <String , Object ?> documentMeta = const {},
290
260
Map <String , List <String >> headers = const {},
291
261
Iterable <QueryEncodable > query = const [],
292
- }) async {
293
- final response = await send (
294
- _baseUri.resource (type, id),
295
- Request .patch (OutboundDataDocument .resource (Resource (type, id)
296
- ..attributes.addAll (attributes)
297
- ..relationships.addAll ({
298
- ...one.map ((key, value) => MapEntry (key, ToOne (value))),
299
- ...many.map ((key, value) => MapEntry (key, ToMany (value))),
300
- })
301
- ..meta.addAll (meta))
302
- ..meta.addAll (documentMeta))
303
- ..headers.addAll (headers)
304
- ..query.mergeAll (query));
305
- return ResourceUpdated (response.httpResponse, response.document);
306
- }
262
+ }) async =>
263
+ ResourceUpdated (await send (
264
+ _baseUri.resource (type, id),
265
+ Request .patch (OutboundDataDocument .resource (Resource (type, id)
266
+ ..attributes.addAll (attributes)
267
+ ..relationships.addAll ({
268
+ ...one.map ((key, value) => MapEntry (key, ToOne (value))),
269
+ ...many.map ((key, value) => MapEntry (key, ToMany (value))),
270
+ })
271
+ ..meta.addAll (meta))
272
+ ..meta.addAll (documentMeta))
273
+ ..headers.addAll (headers)
274
+ ..query.mergeAll (query)));
307
275
308
276
/// Replaces the to-one relationship
309
277
/// identified by [type] , [id] , and [relationship] by setting
@@ -321,15 +289,13 @@ class RoutingClient {
321
289
Map <String , Object ?> meta = const {},
322
290
Map <String , List <String >> headers = const {},
323
291
Iterable <QueryEncodable > query = const [],
324
- }) async {
325
- final response = await send (
326
- _baseUri.relationship (type, id, relationship),
327
- Request .patch (
328
- OutboundDataDocument .one (ToOne (identifier)..meta.addAll (meta)))
329
- ..headers.addAll (headers)
330
- ..query.mergeAll (query));
331
- return RelationshipUpdated .one (response.httpResponse, response.document);
332
- }
292
+ }) async =>
293
+ RelationshipUpdated .one (await send (
294
+ _baseUri.relationship (type, id, relationship),
295
+ Request .patch (
296
+ OutboundDataDocument .one (ToOne (identifier)..meta.addAll (meta)))
297
+ ..headers.addAll (headers)
298
+ ..query.mergeAll (query)));
333
299
334
300
/// Replaces the to-many relationship
335
301
/// identified by [type] , [id] , and [relationship] by setting
@@ -347,15 +313,13 @@ class RoutingClient {
347
313
Map <String , Object ?> meta = const {},
348
314
Map <String , List <String >> headers = const {},
349
315
Iterable <QueryEncodable > query = const [],
350
- }) async {
351
- final response = await send (
352
- _baseUri.relationship (type, id, relationship),
353
- Request .patch (
354
- OutboundDataDocument .many (ToMany (identifiers)..meta.addAll (meta)))
355
- ..headers.addAll (headers)
356
- ..query.mergeAll (query));
357
- return RelationshipUpdated .many (response.httpResponse, response.document);
358
- }
316
+ }) async =>
317
+ RelationshipUpdated .many (await send (
318
+ _baseUri.relationship (type, id, relationship),
319
+ Request .patch (
320
+ OutboundDataDocument .many (ToMany (identifiers)..meta.addAll (meta)))
321
+ ..headers.addAll (headers)
322
+ ..query.mergeAll (query)));
359
323
360
324
/// Removes the to-one relationship
361
325
/// identified by [type] , [id] , and [relationship] ..
@@ -369,14 +333,12 @@ class RoutingClient {
369
333
String relationship, {
370
334
Map <String , List <String >> headers = const {},
371
335
Iterable <QueryEncodable > query = const [],
372
- }) async {
373
- final response = await send (
374
- _baseUri.relationship (type, id, relationship),
375
- Request .patch (OutboundDataDocument .one (ToOne .empty ()))
376
- ..headers.addAll (headers)
377
- ..query.mergeAll (query));
378
- return RelationshipUpdated .one (response.httpResponse, response.document);
379
- }
336
+ }) async =>
337
+ RelationshipUpdated .one (await send (
338
+ _baseUri.relationship (type, id, relationship),
339
+ Request .patch (OutboundDataDocument .one (ToOne .empty ()))
340
+ ..headers.addAll (headers)
341
+ ..query.mergeAll (query)));
380
342
381
343
/// Deletes the resource identified by [type] and [id] .
382
344
///
@@ -399,9 +361,7 @@ class RoutingClient {
399
361
/// This method can be used to send any non-standard requests.
400
362
Future <Response > send (Uri uri, Request request) async {
401
363
final response = await _client.send (uri, request);
402
- if (response.isFailed) {
403
- throw RequestFailure (response.httpResponse, response.document);
404
- }
364
+ if (response.isFailed) throw RequestFailure (response);
405
365
return response;
406
366
}
407
367
}
0 commit comments