metaxy/lib.rs
1#![warn(missing_docs)]
2//! End-to-end typesafe RPC between Rust lambdas on Vercel and any TypeScript frontend.
3//!
4//! This crate is a facade that re-exports the [`metaxy-macro`] proc macros together
5//! with all runtime dependencies they need. Users only have to add two dependencies:
6//!
7//! ```toml
8//! [dependencies]
9//! metaxy = "0.1"
10//! serde = { version = "1", features = ["derive"] }
11//! ```
12//!
13//! # Quick Start
14//!
15//! ```rust,ignore
16//! use metaxy::rpc_query;
17//!
18//! #[rpc_query]
19//! async fn hello(name: String) -> String {
20//! format!("Hello, {}!", name)
21//! }
22//! ```
23
24pub use metaxy_macro::{rpc_mutation, rpc_query, rpc_stream};
25
26pub use serde::{Deserialize, Serialize};
27
28/// HTTP header map for accessing request headers in RPC handlers.
29///
30/// Add a `Headers` parameter to your handler function to receive
31/// the incoming request headers:
32///
33/// ```rust,ignore
34/// use metaxy::{rpc_query, Headers};
35///
36/// #[rpc_query]
37/// async fn secret(headers: Headers) -> Result<String, String> {
38/// let auth = headers.get("authorization")
39/// .and_then(|v| v.to_str().ok());
40/// if auth != Some("Bearer my-token") {
41/// return Err("Unauthorized".into());
42/// }
43/// Ok("secret data".into())
44/// }
45/// ```
46pub type Headers = http::HeaderMap;
47
48mod stream;
49pub use stream::{SendError, StreamSender};
50
51/// Hidden re-exports consumed by code generated by the proc macros.
52/// Not part of the public API — do not depend on these directly.
53#[doc(hidden)]
54pub mod __private {
55 pub use axum;
56 pub use http_body_util;
57 pub use hyper;
58 pub use serde_json;
59 pub use tokio;
60 pub use tower;
61 pub use url;
62 pub use vercel_runtime;
63}