Link Search Menu Expand Document

Fetch

Fetch data from an API.

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  const result = await fetch('https://catfact.ninja/fact')
  const resultJson = await result.json()
  
  return new Response(resultJson.fact)
}

© 2024 Bip.sh, Ltd.