0.4.0 • Published 12 months ago
@http-rpc/client v0.4.0
HTTP RPC Client
Documentation
Full documentation can be found here.
Installation
npm i @http-rpc/client superjson
Usage
./rpcClient.ts
import superjson from 'superjson';
import { createClient } from '@http-rpc/client';
import type { Router } from '../server/rpc/router';
export const client = createClient<Router>({
url: 'http://localhost:3000/rpc',
transformer: superjson,
async headers() {
const token = await getToken();
return {
Authorization: `Bearer ${token}`,
};
},
/* Optional hooks */
onRequest(req) {
console.log(`${req.method?.toUpperCase() ?? 'Unknown'} ${req.url}`);
return req;
},
onResponse(res) {
console.log(`${res.status} ${res.statusText}`);
return res;
},
onError(err) {
console.error(err);
return err;
},
});
import { client } from './rpcClient';
const version = await client.version.get();
// ^? { version: string }
const orders = await client.orders.list({ fields: ['id', 'amount'] });
// ^? { id: number, amount: number }[]
0.2.16
1 year ago
0.3.0
1 year ago
0.4.0
12 months ago
0.2.15
1 year ago
0.2.14
1 year ago
0.2.13
1 year ago
0.2.12
1 year ago
0.2.11
1 year ago
0.2.10
1 year ago
0.2.1
2 years ago
0.2.0
2 years ago
0.2.7
1 year ago
0.2.6
1 year ago
0.2.9
1 year ago
0.2.8
1 year ago
0.2.3
1 year ago
0.2.2
1 year ago
0.2.5
1 year ago
0.2.4
1 year ago
0.1.3
2 years ago
0.1.0
2 years ago
0.1.2
2 years ago
0.1.1
2 years ago
0.0.15
2 years ago
0.0.16
2 years ago
0.0.11
2 years ago
0.0.12
2 years ago
0.0.13
2 years ago
0.0.14
2 years ago
0.0.10
2 years ago
0.0.9
2 years ago
0.0.8
2 years ago
0.0.5
2 years ago
0.0.4
2 years ago
0.0.7
2 years ago
0.0.6
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago