@dappworks/urpc
TypeScript icon, indicating that this package has built-in type declarations

0.0.13 • Public • Published

urpc

To install dependencies:

bun add @dappworks/urpc
import {
  URPC,
  createServerClient,
  createSimpleHttpClient,
} from "@dappworks/urpc";

const urpc = new URPC({
  schemas: {
    sum: URPC.Func({
      input: { a: 0, b: 0 },
      func: ({ input }) => input.a + input.b,
    }),
    foo: URPC.Var({ get: () => data.foo }),
  },
});

// server
const serverClient = createServerClient({ urpc });
const app = new Hono();
app.post("/urpc", async (c) => {
  const body = (await c.req.json()) as any;
  const res = await serverClient.handle(body);
  return c.json(res);
});

// client
const client = createSimpleHttpClient<typeof urpc.schemas>({
  url: "http://localhost:3000/urpc",
});
client.func.call();
client.var.set();
client.schema.loadFull();
client.schema.loadVars();

To run:

bun run index.ts

This project was created using bun init in bun v1.1.3. Bun is a fast all-in-one JavaScript runtime.

Readme

Keywords

none

Package Sidebar

Install

npm i @dappworks/urpc

Weekly Downloads

361

Version

0.0.13

License

MIT

Unpacked Size

32.5 kB

Total Files

4

Last publish

Collaborators

  • jevin_f
  • osdodo
  • dlhtx
  • koishi