downloadJson function
Future<Object?>
downloadJson(
- Uri uri, {
- void headers() = _jsonHeader,
- void cookies()?,
- bool isSuccessfulStatusCode() = _isSuccessfulStatusCode,
- SecurityContext? context,
- Duration connectionTimeout = const Duration(seconds: 10),
- Encoding encoding = utf8,
Download JSON data from the given Uri.
It is possible to configure HttpHeaders and Cookies sent to the server
by providing the functions headers
and cookies
, respectively.
By default, the Accept
header is set to application/json
.
A response is considered successful if the isSuccessfulStatusCode
function returns true
. If it is not, an HttpCodeException is thrown.
By default, defaultSuccessfulStatusCodes is used.
A connectionTimeout
and an Encoding (UTF-8 by default) may be provided.
This method opens a single connection to make a GET request, and closes that connection before returning, so it is not suitable for making several requests to the same server efficiently.
Implementation
Future<Object?> downloadJson(Uri uri,
{void Function(HttpHeaders) headers = _jsonHeader,
void Function(List<Cookie>)? cookies,
bool Function(int) isSuccessfulStatusCode = _isSuccessfulStatusCode,
SecurityContext? context,
Duration connectionTimeout = const Duration(seconds: 10),
Encoding encoding = utf8}) {
return download(uri,
headers: headers,
cookies: cookies,
context: context,
isSuccessfulStatusCode: isSuccessfulStatusCode,
connectionTimeout: connectionTimeout)
.transform(encoding.decoder)
.transform(json.decoder)
.first;
}