fetch method

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

Implementation

@override
Future<ODataResponse<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 T? data;
  late final JSON json;

  try {
    json = jsonDecode(r.body);

    data = options.convert(json);
  } catch (e) {
    data = null;
    try {
      json = {};
    } catch (e) {
      //
    }
  }

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