Fetch Handler

Last updated Apr 23, 2026

Background

Incoming HTTP requests to a Worker are passed to the fetch() handler as a Request object. To respond to the request with a response, return a Response object:

export default {
    async fetch(request, env, ctx) {
        return new Response('Hello World!');
    },
};

Note

The Workers runtime does not support XMLHttpRequest (XHR). Learn the difference between XMLHttpRequest and fetch() in the MDN ↗︎ documentation.

Parameters

  • request Request
  • The incoming HTTP request.
  • env object
  • The bindings available to the Worker. As long as the environment has not changed, the same object (equal by identity) may be passed to multiple requests. You can also import env from cloudflare:workers to access bindings from anywhere in your code.
  • ctx.waitUntil(promisePromise) : void
  • Refer to waitUntil.
  • ctx.passThroughOnException() : void
  • Refer to passThroughOnException.

Was this helpful?

YesNo

On this page

Fetch Handler - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/workers/runtime-apis/handlers/fetch/#page","headline":"Fetch Handler","description":"Handle incoming HTTP requests in Cloudflare Workers using the fetch() handler and return responses.","url":"https://developers.cloudflare.com/workers/runtime-apis/handlers/fetch/","inLanguage":"en","image":"https://developers.cloudflare.com/workers/runtime-apis/handlers/fetch/og.png?v=15275eb5645362e5","dateModified":"2026-04-23","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: Run Workers on a recurring schedule using the scheduled() handler and Cron Triggers. title: Scheduled Handler image: https://developers.cloudflare.com/workers/runtime-apis/handlers/scheduled/og.png?v=72e415a6c5c9189b


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/workers/llms.txt
Use this file to discover all available pages before exploring further.