Getting Started

metaxy is an end-to-end typesafe RPC toolkit for building serverless APIs with Rust on Vercel. Write plain Rust functions, and get a fully typed TypeScript client — no manual sync required.

Installation

Install the CLI

sh
cargo install metaxy-cli

Add the macro crate to your Rust project

sh
cargo add metaxy

Quick Start

Write a Rust lambda

rust
// api/hello.rs
use metaxy::rpc_query;

#[rpc_query]
async fn hello(name: String) -> String {
    format!("Hello, {}!", name)
}

Generate TypeScript types and client

sh
metaxy generate --dir api --output src/lib/rpc-types.ts --client-output src/lib/rpc-client.ts

Call your lambda

  • Any TypeScript frontend
ts
import { createRpcClient } from './rpc-client';

const rpc = createRpcClient({ baseUrl: '/api' });
const greeting = await rpc.query('hello', 'World');
// greeting: string — "Hello, World from Rust on Vercel!"
  • Or 1 of 4 frameworks
ts
import { createQuery } from './rpc.svelte';

let name = $state('World');
const hello = createQuery(rpc, 'hello', () => name);
// hello.data reactively updates when 'name' changes

Try it live

createQuery(rpc, "hello", () => name) — auto-refetches as you type.

How it works

  1. Annotate Rust functions with #[rpc_query] or #[rpc_mutation]
  2. The CLI scans your api/ directory and parses Rust types via syn
  3. TypeScript types and a typed client are generated automatically
  4. Each Rust file deploys as a serverless lambda on Vercel

visit GitHub to learn more about metaxy