Type safety, error handling and D1 access across pages Functions and Workers

Hello everyone, I’m new to Cloudflare Workers/Pages and I'm working with a project using Qwik City (the framework for Qwik, similar to Next/SolidStart/Nuxt etc). Qwik City provides its own API endpoints, and the application will be hosted on Cloudflare Pages. I'm trying to determine the best approach for using D1 in this setup.

Is it possible for a Qwik City function running on Cloudflare Pages to call a separate Cloudflare Worker running on Hono through a service binding (Pages → Worker → D1 )? If so, would this behave normally, and would the D1 smart placement optimizations still work as expected inside the Hono Worker?

I'm also looking for guidance on recommended patterns for error handling when calling another Worker over a service binding.

Lastly, what's the recommended way to handle type safety between my Qwik City API routes and the Worker? Is it possible to use Hono’s RPC client for this, and if so, should I be using the HTTP mode or the RPC mode when invoking the Worker through a service binding?

I'm deciding between accessing D1 directly within Qwik City or creating a dedicated Hono API Worker, so any guidance or best practices would be greatly appreciated.
Was this page helpful?