Skip to content

Arri RPC is a code-first RPC framework for end-to-end type safety in any language

License

Notifications You must be signed in to change notification settings

modiimedia/arri

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WARNING: Breaking changes are likely to happen until v1.0 is released

Arri RPC

Discord

Arri RPC is a code-first RPC framework. Type-safe clients get generated directly from your server code meaning you never need to manually write another client again.

Click here to get started with your backend language of choice.

arri_type_generation_demo_compressed.mp4

Table of Contents

Server Implementations

I'm currently finishing up the Go server implementation. After that is stable I have the following languages on my shortlist for the next potential server implementation:

  • rust
  • dart
  • zig

See this guide for information on how to implement your own Arri server

Client Generators

Below are the language client generators that are planned to have first party support. This chart tracks the current progress on implementations for these clients. For those interested in creating their own generators, see this guide.

Language HTTP SSE
Typescript
Dart
Rust
Kotlin ✅**
Swift ✅**
Go
Python

✅ completed

🚧 in progress

** SSE for Kotlin and Swift are working but they still have some rough edges

Other Tooling

  • Arri CLI - CLI tool for run code generators and managing dependencies
  • @arrirpc/schema - Arri type builder used to define types that can be generated in multiple languages. It also doubles as a parsing and serialization library that can be used on a NodeJS backend.
  • @arrirpc/eslint-plugin - Useful eslint rules when making Arri Type Definitions

Manually Creating an App Definition

Even though Arri focuses primarily on a code-first approach it allow you to manually create app definitions in the event that you have a server implementation that isn't supported. Once your app definition is created you simply need to point the CLI to the app definition file. This file can be can be a typescript file, JSON file, or a JSON http endpoint.

arri codegen ./AppDefinition.ts

arri codegen ./AppDefinition.json

arri codegen https://myapi.com/rpcs/__definition # must accept a GET request

Before running this command. Make sure you have an arri config created already.

Example Config:

// arri.config.ts
import { defineConfig, generators } from "arri";

export default defineConfig({
    generators: [
        generators.dartClient({
            // options
        }),
        generators.kotlinClient({
            // options
        }),
        generators.typescriptClient({
            // options
        }),
    ],
});

Typescript App Definition (Recommended)

Arri comes with some useful helpers that reduces the boilerplate of manually creating a JSON definition file. Additionally the validators created with Arri Schema can be used throughout your app.

// AppDefinition.ts
import { createAppDefinition } from "arri";
import { a } from "@arrirpc/schema";

const HelloParams = a.object("HelloParams", {
    message: a.string(),
});

const HelloResponse = a.object("HelloResponse", {
    message: a.string(),
});

export default createAppDefinition({
    procedures: {
        sayHello: {
            transport: "http",
            method: "post",
            path: "/say-hello",
            params: HelloParams,
            response: HelloResponse,
        },
    },
});

Additionally if you only need cross language types, you can skip defining procedures all together and just pass in models to the helper.

// AppDefinition.ts
import { createAppDefinition } from "arri";
import { a } from "@arrirpc/schema";

const HelloParams = a.object("HelloParams", {
    message: a.string(),
});

const HelloResponse = a.object("HelloResponse", {
    message: a.string(),
});

export default createAppDefinition({
    definitions: {
        HelloParams,
        HelloResponse,
    },
});

Now arri codegen ./AppDefinition.ts will only generate types for each client defined in the arri config.

JSON App Definition

JSON app definitions are something that would normally be automatically generated by an implementation of ARRI-RPC. Manually creating a JSON app definition is more terse and more subject to human error than the typescript alternative.

{
    "schemaVersion": "<current-schema-version>",
    "procedures": {
        "sayHello": {
            "transport": "http",
            "method": "get",
            "path": "/say-hello",
            "params": "HelloParams",
            "response": "HelloResponse"
        }
    },
    "definitions": {
        "HelloParams": {
            "properties": {
                "message": {
                    "type": "string",
                    "metadata": {}
                }
            },
            "metadata": {
                "id": "HelloParams",
                "metadata": {}
            }
        },
        "HelloResponse": {
            "properties": {
                "message": {
                    "type": "string",
                    "metadata": {}
                }
            },
            "metadata": {
                "id": "HelloResponse"
            }
        }
    }
}

How To Contribute

Contributions are welcome!

Please read the contribution guide which will guide you through the entire workflow of how to build the source code, how to run the tests, and how to contribute changes to the Arri RPC codebase. Also feel free to reach out on discord if you have any other additional questions.