0 purchases
trpc client
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:
// Import package
import "package:trpc_client/trpc_client.dart";
// Instantiate the client
final client = TRPCClient(
baseUri: "https://example.com/trpc",
headers: {"x-trpc-source": "Dart App"},
);
copied to clipboard
Now you can query, and mutate, with type safety:
final response = await client.query<Map<String, dynamic>>("route", payload: {"userId": "example"});
if (response.isError) {
print(response.errors);
} else {
final data = response.successResponse.data;
}
copied to clipboard
Usage with Riverpod (Provider) #
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;
}
copied to clipboard
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
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.