---
title: Framework callers
description: Bind a caller to a request in Hono, SvelteKit, or Next.js.
---

A framework caller runs a function as the scope you build for the request.

1. **Build the scope**

    Resolve the actor and account from trusted request data. Use the app's signed-out scope when the request permits guests.

2. **Bind the caller and run the function**

    Bind `registry.as(scope)` once per request. Run only functions with an `authorize` policy.

    ```ts
    const scope = await scopeFrom(request);
    const caller = registry.as(scope);
    const booking = await caller.run(bookings.confirm, { bookingId });
    ```

3. **Connect your framework**

    **Hono**

    ```ts
    app.use(async (c, next) => {
      c.set("caller", registry.as(await scopeFrom(c.req.raw)));
      await next();
    });

    app.post("/bookings/:id/confirm", async (c) =>
      c.json(await c.var.caller.run(bookings.confirm, { bookingId: c.req.param("id") })),
    );
    ```

    **SvelteKit**

    ```ts
    // hooks.server.ts
    export const handle = async ({ event, resolve }) => {
      event.locals.caller = registry.as(await scopeFrom(event.request));
      return resolve(event);
    };

    // +page.server.ts
    export const actions = {
      confirm: ({ params, locals }) =>
        locals.caller.run(bookings.confirm, { bookingId: params.id }),
    };
    ```

    **Next.js**

    ```ts
    "use server";

    export async function confirmBooking(bookingId: string) {
      const caller = registry.as(await scopeFromCookies());
      return caller.run(bookings.confirm, { bookingId });
    }
    ```

    To deliver jobs after the response, set `waitUntil: (p) => after(() => p)` on the registry.

Each request gets the confirmed booking when its scope passes the policy.

## See also

- [Scope](/docs/concepts/scope)
- [HTTP routes](/docs/guides/http)
- [Cloudflare Workers](/docs/guides/cloudflare)
