What are the advantages of using Cloudflare's Fetch vs Node's Fetch?

I want to learn more about what the exact use cases and benefits are for calling fetch on a service binding vs using Node's Fetch directly as well as if I am doing it correctly. Here is some sample code: // fuseApi = env.SOME_API ... a service binding from wrangler.jsonc + generated worker types const apiResp = await this.fuseApi.fetch( new Request(new URL(eventApiPath, 'http://dummy').toString(), { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': 'this.fuseApiKey', }, body: JSON.stringify(eventPayload), }) ); Is the purpose of this fetch wrapper that some internal magic overrides the fake url and uses internal DNS resolvers for worker to worker communication? Are there other benefits regarding logs, performance, billing, etc? Is my sample code the proper and expected way to do worker to worker calls, or is there a better way? I did read through these docs, https://developers.cloudflare.com/workers/runtime-apis/fetch/, but I still feel unsure about how I am doing all this and if I am taking advantage of this Fetch wrapper to its fullest. Thank you experts and those wanting to help 🙂
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?