fetch method

  1. @override
Future<ODataCollectionResponse<T>?> fetch()
override

Implementation

@override
Future<ODataCollectionResponse<T>?> fetch() async {
  final http.Request req = http.Request(options.method, Uri.https(baseUrl, path, queries()));

  req.body = options.requestBody.toString();

  headers.forEach((key, value) {
    req.headers[key] = value;
  });

  http.StreamedResponse streamedResponse = await req.send();
  http.Response r = await http.Response.fromStream(streamedResponse);

  late final BuiltList<T>? data;
  JSON json = {};

  try {
    json = jsonDecode(r.body);

    data = options.convert(json["value"]);
  } catch (e) {
    data = null;
  }

  return ODataCollectionResponse<T>(
    uri: req.url,
    response: r,
    json: json,
    collectionData: data,
    count: json["@odata.count"],
    statusCode: r.statusCode,
    context: json["@odata.context"],
    query: this,
    request: req,
  );
}