toRequest static method

HttpRequest toRequest({
  1. dynamic from,
})

Implementation

static HttpRequest toRequest({dynamic from}) {
  var json = tryCast<Map<Object?, Object?>>(from);
  var headersRaw = tryCast<Map<Object?, Object?>>(json?["headers"]);
  Map<String, String> reqHeaders = {};

  headersRaw?.forEach((key, value) {
    reqHeaders[key.toString()] = value.toString();
  });

  Uri reqUrl = Uri.parse(json?["url"]?.toString() ?? "");
  HttpMethod? reqMethod = httpMethodFrom(json?["method"]?.toString());
  String? reqBody = json?["body"]?.toString();

  return HttpRequest(
    reqUrl,
    reqMethod ?? HttpMethod.POST,
    reqHeaders,
    reqBody,
  );
}