RPC framework
Full stack APIs at the speed of light
Write a plain TypeScript function, and it is an API route. Params are validated, and params and results make the JSON round trip for you. The client calls remote routes like local async functions, with full types and autocompletion.
// packages/private-examples/src/_homepage/home-rpc-server.tsimport {createMionRouter, Routes} from '@mionjs/router';import {startNodeServer} from '@mionjs/platform-node';const mion = createMionRouter();Automatic validation and JSON round trip from TypeScript typesinterface User { id: number; name: string; createdAt: Date; tags: Set<string>;}A plain function is a route; its params arrive fully validatedconst routes = { getUser: mion.query((ctx, id: number): User | null => { if (id !== 1234) return null; return { id: 1234, name: 'John', createdAt: new Date(), tags: new Set(['admin']), }; }), // ...other routes} satisfies Routes;export const myApi = mion.initRoutes(routes);export type MyApi = typeof myApi;startNodeServer({port: 3000});// packages/private-examples/src/_homepage/home-rpc-client.tsimport {initClient} from '@mionjs/client';import type {MyApi} from './home-rpc-server.ts';const {routes} = initClient<MyApi>({ baseURL: 'http://localhost:3000',});Remote routes are called like local async functions, fully typedconst [user, error] = await routes.- getUser
getUser(1234).call();if (user) { user.User.createdAt: DatecreatedAt; // @annotate: Native classes like Set come back as real values user.User.tags: Set<string>tags;}// Type error: id must be a number// @ts-expect-error -- shown on purpose; the assertion fails the build if this ever stops erroringroutes.getUser('1234').call();RunTypes
Bringing TypeScript to runtime
Everything is generated at compile time, derived from your types:
// packages/private-examples/src/_homepage/home-run-types.tsimport {createValidateFn, createJsonEncoderFn} from '@mionjs/run-types';import {createMockDataFn} from '@mionjs/run-types/mocking';interface User { id: string; name: string; createdAt: Date; tags: Set<string>;}Create precompiled functions directly from TypeScript typesconst isUser = createValidateFn<User>();const encodeUser = createJsonEncoderFn<User>();const mockUser = createMockDataFn<User>();Generate mock data - respects type structureconst const user: Useruser = mockUser();Validate data at runtimeisUser(user);JSON round trip for complex types (Date, Set, unions)const const json: stringjson = encodeUser(user);Performance from the ground up!
Speed and memory efficiency are a design goal, measured from the first commit. Validation and the JSON round trip are compiled at build time, so your app imports no runtime library for them: smaller bundles, faster cold starts and less memory, which makes mion a natural fit for edge and serverless runtimes. The RPC server is benchmarked against express, fastify, hono and friends, and RunTypes against the fastest validators. Every number is generated on deploy from the code in this repository.
Tested to the highest standard
Every function mion generates for you is tested, and so is the build step that writes them. The suite covers validation, JSON round trip, mock data and reflection, on every type shape we could think of.