fetch function

Future<Response> fetch(
  1. Resource resource, {
  2. CloudflareRequestInit? cf,
  3. String? method,
  4. Headers? headers,
  5. Object? body,
  6. String? referrer,
  7. ReferrerPolicy? referrerPolicy,
  8. RequestMode? mode,
  9. RequestCredentials? credentials,
  10. RequestCache? cache,
  11. RequestRedirect? redirect,
  12. String? integrity,
  13. bool? keepalive,
  14. AbortSignal? signal,
  15. RequestDuplex? duplex,
})

Implementation

Future<Response> fetch(
  Resource resource, {
  CloudflareRequestInit? cf,
  String? method,
  Headers? headers,
  Object? body,
  String? referrer,
  interop.ReferrerPolicy? referrerPolicy,
  interop.RequestMode? mode,
  interop.RequestCredentials? credentials,
  interop.RequestCache? cache,
  interop.RequestRedirect? redirect,
  String? integrity,
  bool? keepalive,
  AbortSignal? signal,
  interop.RequestDuplex? duplex,
}) async {
  final init = interop.RequestInit(
    method: method,
    headers: headers?.delegate,
    body: body,
    referrer: referrer,
    referrerPolicy: referrerPolicy,
    mode: mode,
    credentials: credentials,
    cache: cache,
    redirect: redirect,
    integrity: integrity,
    keepalive: keepalive,
    signal: signal?.delegate,
    duplex: duplex,
  );

  // Attach the non-standard Cloudflare properties to the Request Init object.
  if (cf != null) {
    init.cf = cf.delegate;
  }

  return responseFromJsObject(
    await js_util.promiseToFuture(
      interop.fetch(
        interop.requestFromResource(resource),
        init,
      ),
    ),
  );
}