Check which HTTP method and URL you sent

A small wrapper that logs each request and how long it took. Handy while developing.

AJAX · Check which HTTP method and URL you sentIntermediate
async function loggedFetch(url, options = {}) {
  const started = performance.now();
  const method = options.method || 'GET';
  try {
    const res = await fetch(url, options);
    console.log(method, url, res.status, Math.round(performance.now() - started) + ' ms');
    return res;
  } catch (e) {
    console.warn(method, url, 'FAILED', e.message);
    throw e;
  }
}
debuggingdevtoolsnetworkfetch