
Better Call Better call is a tiny web framework for creating endpoints that can be invoked as a normal function or mounted to a router to be served by any web standard compatible server (like Bun, node, nextjs, sveltekit…) and also includes a typed RPC client for typesafe client-side invocation of these endpoints. Built for typescript and it comes with a very high performance router based on rou3. Install bash pnpm i better-call Make sure to install standard schema compatible validation library like zod. bash pnpm i zod Usage The building blocks for better-call are endpoints. You can create an endpoint by calling createEndpoint and passing it a path, options and a handler that will be invoked when the endpoint is called. “`ts import { createEndpoint, createRouter } from "better-call" import { z } from "zod" const createItem = createEndpoint("/item", { method: "POST", body: z.object({ id: z.string() }) }, async (ctx) => { return { item: { id: ctx.body.id } } }) // Now you can call the endpoint just as a normal function. const item = await createItem({ body: { id: "123" } }) “` OR you can mount the endpoint to a router and serve it with any web standard compatible server. The example below uses Bun “`ts const router = createRouter({ createItem }) Bun.serve({ fetch: router.handler }) “` Then you can use the rpc client to call the endpoints on client. “`ts //client.ts import type { router…Read More
References
Back to Main