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:
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
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.
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/#interfacesCloudflare Docs
Service bindings - Runtime APIs · Cloudflare Workers docs
Facilitate Worker-to-Worker communication.