Unified Communication
Seamlessly bridges frontend and backend applications, creating a harmonized communication environment
Unify Frontend-Backend Interactions
RPC layer on top of http with full typesafety and more
a simple example of how to use @http-rpc/server
with fastify
:
import Fastify from 'fastify';
import { createRoute } from '@http-rpc/server';
import { rpcFastify, FastifyContext } from '@http-rpc/server/adapters/fastify';
const fastify = Fastify({
logger: true,
});
const publicRoute = createRoute<FastifyContext>();
const router = {
version: publicRoute.get(() => {
return { version: 'v1.0.0' };
}),
};
export type Router = typeof router;
fastify.register(rpcFastify, {
prefix: '/rpc',
router,
});
await fastify.listen({ port: 3000, host: '0.0.0.0' });
a simple example of how to use @http-rpc/client
:
import { createClient } from '@http-rpc/client';
import type { Router } from './server';
const client = createClient<Router>({
url: 'http://localhost:3000/rpc',
});
const versionData = await client.version.get();
// ^? { version: string }