Skip to main content

2 posts tagged with "Sockets"

View All Tags

What if WebSockets felt like tRPC?

· 7 min read
Maciej Pyrc
Creator of Hyper Fetch | @BetterTyped
Tutorial

What if WebSockets felt like tRPC?

And SSE. And Firebase. And REST. One schema, every protocol.

sdk.ts×
sdk.chat.$roomId.$listener
.setParams({ roomId: "general" })
.listen(({ data }) => addMessage(data));

tRPC made HTTP feel like calling a local function. The proxy pattern that powers it - a TypeScript type as the schema, a runtime Proxy that materializes typed methods on demand - is the most ergonomic API client pattern we have. But it stops at HTTP. Real apps also speak WebSockets, SSE, and Firebase, and each transport drops you back into stringly-typed handlers, untyped event names, and bespoke client APIs. We applied the same pattern across all of them.

SDK Configuration

· 4 min read
Maciej Pyrc
Creator of Hyper Fetch | @BetterTyped
Tutorial

SDK Configuration

One config. Every endpoint. Fully typed.

sdk.ts×
const sdk = createSdk(client).$configure({
"users.$get": { cache: true, cacheTime: 30000 },
"/admin/*": { auth: true, retry: 0 },
});

Your API schema generates a fully typed SDK, but the generated code only knows about endpoints and types. Real projects still need caching policies, retry rules, auth settings, and response mappers. $configure lets you inject all of that into the SDK in one place, so every request comes pre-configured the moment you access it. It also makes testing easier by letting you swap in mocks without tools like msw or nock.