Request constructor
Request({})
Creates a Request
url
must not be encoded and can include query parameters
urlQueryParameters
may be added and will be appended to the url
headers
an optional map of HTTP request headers
post
if set, uses POST instead of GET. Post must be one of the
following:
- a String: POST request with
post
as the body, encoded in utf8 - a Map: will be jsonEncoded to a String and set as the POST body
- a List of bytes: will be converted to a String using String.fromCharCodes and set as the POST body
- a List: map will be jsonEncoded to a String and set as the POST body
retries if >0 will retry a failed download this many times
Implementation
Request(
{required String url,
Map<String, String>? urlQueryParameters,
Map<String, String>? headers,
String? httpRequestMethod,
post,
this.retries = 0,
DateTime? creationTime})
: url = urlWithQueryParameters(url, urlQueryParameters),
headers = headers ?? {},
httpRequestMethod =
httpRequestMethod?.toUpperCase() ?? (post == null ? 'GET' : 'POST'),
post = post is Uint8List
? String.fromCharCodes(post)
: post is Map || post is List
? jsonEncode(post)
: post,
retriesRemaining = retries,
creationTime = creationTime ?? DateTime.now() {
if (retries < 0 || retries > 10) {
throw ArgumentError('Number of retries must be in range 1 through 10');
}
if (!validHttpMethods.contains(this.httpRequestMethod)) {
throw ArgumentError(
'Invalid httpRequestMethod "${this.httpRequestMethod}": Must be one of ${validHttpMethods.join(', ')}');
}
}