The best way to control Claude Code, Codex and more from any computer or phone
| 1 | # Cloudflare Federated API |
| 2 | |
| 3 | One URL, one Effect `HttpApi`, four Workers — and no gateway Worker in the request path. |
| 4 | |
| 5 | ``` |
| 6 | api.example.com/products* → Products (KV: read catalog) |
| 7 | api.example.com/orders* → Orders (KV: read catalog, read/write orders) |
| 8 | api.example.com/admin/* → Admin (KV: write catalog) |
| 9 | api.example.com/* → Home (custom domain, no bindings) |
| 10 | ``` |
| 11 | |
| 12 | `Home` owns the hostname as a custom domain (DNS record + certificate). The other Workers claim paths with zone routes, which Cloudflare matches before custom domains — so each request goes straight to the Worker that owns its path, and each Worker binds only the access its handlers need. |
| 13 | |
| 14 | ```ts |
| 15 | export default class Products extends Cloudflare.Worker<Products>()( |
| 16 | "Products", |
| 17 | { |
| 18 | main: import.meta.url, |
| 19 | routes: [{ pattern: `${HOSTNAME}/products*` }], |
| 20 | }, |
| 21 | Effect.gen(function* () { |
| 22 | const catalog = yield* Cloudflare.KV.ReadNamespace(Catalog); |
| 23 | // ...serve the `products` group of the shared HttpApi |
| 24 | }), |
| 25 | ) {} |
| 26 | ``` |
| 27 | |
| 28 | The API is defined once in `src/Api.ts`. Each Worker serves one group; clients use the combined `StoreApi` against the single URL. |
| 29 | |
| 30 | ## Dev |
| 31 | |
| 32 | ```sh |
| 33 | bun alchemy dev |
| 34 | ``` |
| 35 | |
| 36 | `alchemy dev` emulates the zone routes locally: the `url` output (`Home`'s local URL) applies the same routing table, so `http://localhost:<port>/orders` runs the local `Orders` Worker. |
| 37 | |
| 38 | ## Deploy |
| 39 | |
| 40 | Set `API_HOSTNAME` to a hostname in a zone on your Cloudflare account: |
| 41 | |
| 42 | ```sh |
| 43 | API_HOSTNAME=api.your-domain.com bun alchemy deploy |
| 44 | ``` |