0.4.0 • Published 10 months ago

@http-rpc/client v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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

10 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

1 year ago

0.2.0

1 year 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

1 year ago

0.1.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.15

1 year ago

0.0.16

1 year ago

0.0.11

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago