function calling a worker with data

I think I'm missing some basic understanding of how functions and workers can work together. I've binded my worker to my function as mentioned here https://developers.cloudflare.com/pages/functions/bindings/#service-bindings. But the only usage example is:
return context.env.SERVICE.fetch(context.request);
return context.env.SERVICE.fetch(context.request);
But, I don't want to just forward the request sent to the function. I want to send the worker JSON data for it to send an email, and in the function I redirect to a confirmation page. I'm unclear how to interact with the worker from the function
2 Replies
sia
siaOP4mo ago
Specifically, how to send data to the worker from the function. It would be nice to await a response from the worker but I could skip that if needed.
wilsonianb
wilsonianb4mo ago
Unless functions have some extra limitations, I'm guessing you can use either RPC or do fetch with a request with your JSON data. https://developers.cloudflare.com/workers/runtime-apis/bindings/service-bindings/#interfaces
Cloudflare Docs
Service bindings - Runtime APIs · Cloudflare Workers docs
Facilitate Worker-to-Worker communication.
Want results from more Discord servers?
Add your server