Introduction

About mion

Learn what mion is and why you should use it.

Full Stack APIs at the speed of light 🚀

WTF are Full Stack APIs?
Is the concept of fully integrate your API functions into your frontend application as if they were local functions. All the complexity of http requests, methods, validation, serialization, etc... is abstracted away and you can just call your APIs as if they were local functions.
With mion, you can quickly build APIs that are type-safe, with automatic validation and serialization out of the box.

Quick Sample

server.ts
import {initMionRouter, route, Routes} from '@mionkit/router';
import {startNodeServer} from '@mionkit/node';

const routes = {
    // fully validated params
    sayHello: route((ctx, name: string): string => {
        return `Hello ${name}!`;
    }),
} satisfies Routes;

export const myApi = await initMionRouter(routes);
startNodeServer({port: 3000});
export type MyApi = typeof myApi;
client.ts
import {initClient} from '@mionkit/client';
import type {MyApi} from './about-server.ts';

const {routes} = initClient<MyApi>({
    baseURL: 'http://localhost:3000',
});

async function example() {
    // Call server method as if it were a local function
    const [hello] = await routes.sayHello('World').call();
    console.log(hello); // hello world
}
example();
That's all you need to create a fully typed API with automatic validation and serialization out of the box. Use any RPC function as if they were local async functions.

Why Another Framework?

  • There are not many frameworks that offer Full Stack APIs will all the features from mion and that take full advantage Typescript type system.
  • Serverless applications have different requirements compared to conventional servers.
  • mion takes advantage of a new generation of tools (Deepkit) that bring types to runtime allowing automatic validation/serialization out of the box and a whole new set of possibilities.
  • Generic HTTP frameworks have a lot of baggage that is not required for modern APIs. Url or path params, multiple mime-types, file uploads, multipart/form-data and many other features that generic HTTP frameworks must support just make them more complicated and slow.

mion addresses these challenges by offering a lightweight and opinionated framework focused on simplicity and developer experience.

RunTypes

mion uses Typescript types to generate functions for validation and serialization. No need for extra validation libraries or separate schemas, no need to write extra code to serialize/deserialize data. With runTypes mion creates Highly optimized functions straight from Typescript. These functions are transparently shared between the client and the server, so validation and serialization is done both on the browser and the server. Typescript is the best language to describe types and should be the source of truth for types, so mion fixes Typescript biggest limitation and bring types to runtime.

Automatic Serialization & Validation

When compiling typescript we emit type metadata thats can be accessed at runtime. Then mion uses that metadata at runtime to create JIT functions for automatic validation and serialization, those functions can be run both in the server and the client transparently, the client handled all the complexity of http requests, methods, validation, serialization, etc....

RPC "Like"

mion is designed with a Remote Method Call (RPC) style where functions are the primary interface and there are no abstractions over the API data.

We use the term RPC "Like" to highlight that mion does not use an RPC or custom protocol. mion operates over HTTP yet it uses an RPC style routing.

Routing

mion's router is lightweight and fast. Unlike traditional routers, the HTTP method is not relevant, there are no parameters in the URL, and data is sent and received via the request body or headers. mion's router leverages a simple in-memory map for route lookup, making it extremely fast.

Fast

We have prioritized and tracked performance during the development of the framework, we even discarded features or experiments when we observed a performance degradation. Our goal is to have similar performance to fastify which we consider the gold standard in node.js frameworks!

Benchmarks

We know, benchmarks can be deceiving... But if you don't keep performance in check you end up like Internet Explorer! We use benchmarks to ensure mion performance is kept in check.
Check out the Benchmarks page for more info!