trpc_client 0.1.1
trpc_client: ^0.1.1 copied to clipboard
A minimal trpc client for Dart and Flutter.
trpc_client #
A simple trpc client for Dart Applications. It's minimal, dependency-free (only depends on dart's own http library), and works perfectly with flutter.
Features #
- Run Query and Mutate operations against your tRPC server (expressjs, Next.js, Cloudflare Worker, ...)
Usage #
You just need to instantiate the TRPCClient
class with the trpc base endpoint. You can optionally pass headers:
final client = TRPCClient(
baseUri: "https://example.com/trpc",
headers: {"x-trpc-source": "Dart App"},
);
I recommend using it with riverpod, to make authentication easier:
@riverpod
TRPCClient trpcClient(TrpcClientRef ref) {
final sessionId = ref.watch(sessionIdProvider);
final client = TRPCClient(
baseUri: "https://example.com/trpc",
headers: {"Authorization": "Bearer $sessionId"},
);
return client;
}
Additional information #
TOOD #
- ❌ Better README.md
- ❌ Support for batching
- ❌ Write tests with real tRPC server
- ❌ Linter Rules
- ❌ Docs?
- ❌ Somehow generate definitions from ts?
PR's are welcome :D