| 1 | # Facets |
| 2 | |
| 3 | This example starts a Worker at runtime with the Worker Loader, and it runs a |
| 4 | Durable Object class from that Worker as a facet of a Durable Object. The facet |
| 5 | counts the requests in its own SQLite database with the synchronous KV API, and |
| 6 | celld replicates that database with the root object. The parent passes a |
| 7 | parameterized `ctx.exports` Service Binding through `WorkerCode.env`, so the |
| 8 | loaded Worker can call the parent entrypoint. |
| 9 | |
| 10 | The `worker_loaders` key of `wrangler.jsonc` declares the Worker Loader, and |
| 11 | the entry in this example puts the binding at `env.LOADER`. Cloudflare can |
| 12 | still change the Worker Loader API, so this example needs no setting but it can |
| 13 | change. Start the example: |
| 14 | |
| 15 | ```sh |
| 16 | celld dev . |
| 17 | curl http://127.0.0.1:9876/ |
| 18 | ``` |
| 19 | |
| 20 | Each request answers the count and the parent entrypoint's greeting. The count |
| 21 | survives a restart of the command. |