Fetchable is a type interface that request entry point ES modules may implement to ensure compatiblity with many platforms, runtimes, frameworks, and other tools. It is designed to be simple, flexible, and extensible. It is documented here as a reference to encourage adoption and interoperability across the ecosystem.
Definitions
A Fetchable module is an ECMAScript module whose default export is an
object with a fetch property conforming to the
FetchHandler interface (ref). This method is intended to be invoked to handle an incoming HTTP request.
interface Fetchable {
default: {
fetch(request: Request, ...extra: unknown[]): Promise<Response> | Response
}
}
The first argument MUST be a Web Request. The return value MUST be either a Web Response or a promise resolving to a Web Response.
Invokers may pass additional custom arguments. Fetchable modules may have additional properties on their default export.
Example
// entrypoint.ts
export default {
async fetch(req: Request): Promise<Response> {
return new Response(`Hello, ${req.headers.get("User-Agent")}!`)
}
}
Interoperable with...
- Acorn
- Bun
- Cloudflare Workers
- Deno
- Deno Deploy
- Elysia
- H3
- Hono
- itty-router
- Netlify Functions (coming soon)
- Nitro
- Oak
- RedwoodSDK
- RivetKit
- SolidStart (coming soon)
- srvx
- TanStack Start
- Vercel Functions