Skip to main content

One post tagged with "SSE"

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.