metaxy 0.1.3

End-to-end typesafe RPC between Rust and TypeScript
Documentation

metaxy

Crates.io docs.rs License: MIT OR Apache-2.0

End-to-end typesafe RPC between Rust lambdas on Vercel and any TypeScript frontend.

This is the main entry point for the project — a facade crate that re-exports the metaxy-macro proc macros together with all runtime dependencies they need.

Installation

[dependencies]
metaxy = "0.1"
serde = { version = "1", features = ["derive"] }

That's it — no need to add vercel_runtime, serde_json, tokio, url, or http-body-util manually.

Usage

Query (GET)

use metaxy::rpc_query;

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

The macro generates a full Vercel handler that:

  • Reads name from the ?input=<JSON> query parameter
  • Returns { "result": { "type": "response", "data": "Hello, World!" } }
  • Responds to OPTIONS with CORS preflight headers
  • Rejects non-GET methods with 405

Query without input

use metaxy::rpc_query;

#[rpc_query]
async fn version() -> String {
    "1.0.0".to_string()
}

Mutation (POST)

use metaxy::rpc_mutation;
use serde::Deserialize;

#[derive(Deserialize)]
struct CreateUserInput {
    name: String,
    email: String,
}

#[rpc_mutation]
async fn create_user(input: CreateUserInput) -> String {
    format!("Created user {}", input.name)
}

Mutations read input from the JSON request body and only accept POST.

Returning Result

use metaxy::rpc_query;

#[rpc_query]
async fn find_user(id: u32) -> Result<String, String> {
    if id == 0 {
        Err("user not found".into())
    } else {
        Ok(format!("user_{}", id))
    }
}
  • Ok(value) → HTTP 200 success response
  • Err(error) → HTTP 400 error response

Response format

Success (HTTP 200):

{
  "result": {
    "type": "response",
    "data": <value>
  }
}

Error (HTTP 400):

{
  "error": {
    "type": "error",
    "message": "<error description>"
  }
}

Constraints

  • Functions must be async.
  • Each function accepts at most one parameter.
  • Input types must implement serde::Deserialize.
  • Output types (and Ok types in Result) must implement serde::Serialize.

Re-exports

For convenience, the crate re-exports serde::{Serialize, Deserialize}, so you can write use metaxy::Serialize; if you prefer.

Related crates

  • metaxy-macro — the proc macros themselves (re-exported by this crate).
  • metaxy-cli — CLI that scans your #[rpc_query] / #[rpc_mutation] functions and generates TypeScript types and a typed client.

License

MIT OR Apache-2.0