json-api-dart
json-api-dart copied to clipboard
Throw error when decode the body: Bad state: Stream has already been listened to.
Throw error when decode the body:
final response = await client.jsonapiClient.fetchCollection('node--gallery', query: [Query({'include': ['field_gallery_image']})]);
final json = await response.httpResponse.body.decode(utf8);
Bad state: Stream has already been listened to.
I can find a way to get the response body as a dart String, when I try to use the japx package to flattens the response.
I think it is impossible to read the http response stream twice. However the raw parsed json is available as response.document. Can you give more details about your use case? Why do you need to decode the raw response again?
package:json_api is amazing, I love it, but the package:japx provides a more efficient way to read the response of json api.
So i want to get the raw json to construct a japx object, unfortunate package:json_api doesn't return the raw response body:
https://github.com/f3ath/json-api-dart/blob/master/lib/src/client/response/collection_fetched.dart
response.document
I think it is impossible to read the http response stream twice. However the raw parsed json is available as
response.document. Can you give more details about your use case? Why do you need to decode the raw response again?
Unfortunate the response.document also can not be accessed from collection_fetched.dart
Ah I see what you mean. I will tweak the RoutingClient responses and expose the raw document, should be straightforward enough. Meanwhile you can try using the low-level Client class as a workaround.
Ah I see what you mean. I will tweak the RoutingClient responses and expose the raw document, should be straightforward enough. Meanwhile you can try using the low-level Client class as a workaround.
Thank you for you help, but if I use the low-level Client class, why do I use json-api-dart package, haha
I've fork this repository, and try to contribute a branch for this issuse, I'll come back soon.
How about include the https://pub.dev/packages/japx package to provide more efficient way to read jsonapi response in our json_api package?
How about include the https://pub.dev/packages/japx package to provide more efficient way to read jsonapi response in our
json_apipackage?
I don't see significant benefits in including it as a dependency. Rather this package should be flexible enough to allow combining it with other tools if needed.
I've exposed the rawResponse object, let me know if that helps: https://pub.dev/documentation/json_api/latest/client/CollectionFetched/rawResponse.html