© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Cloudflare DevelopersCD
Cloudflare Developers•2y ago•
1 reply
limikael

Worker uploaded via API: fetch vs service worker

I have been upoading workers via the api using this API: https://developers.cloudflare.com/api/operations/worker-script-upload-worker-module

There are 2 types of runtime APIs when using workers, I think they are referred to as "fetch" and "service worker". What I mean is that I can write my worker like this:

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


Or:
addEventListener("fetch", (event) => event.respondWith(new Response("hello")));
addEventListener("fetch", (event) => event.respondWith(new Response("hello")));


I think the first one is preferred (fetch). However, when I upload to the API, only the the other one works (service worker). I'm therefore assuming that the service worker API is what is actually being run, it is a lower level thing. The fetch functionality is added by wrangler when it builds. So when uploading via the API we have to use the service worker API. Which is totally ok, just want to check if this is the case?
Cloudflare API Documentation
Interact with Cloudflare's products and services via the Cloudflare API
Cloudflare Developers banner
Cloudflare DevelopersJoin
Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news
85,042Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Workern to worker fetch 1042
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
3mo ago
Error when calling worker via service binding
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
9mo ago
Worker to Worker fetch
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
3y ago
Enable workers.dev route for worker deployed via API
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
2y ago