Coder Social home page Coder Social logo

k8w / tsrpc Goto Github PK

View Code? Open in Web Editor NEW
1.8K 55.0 187.0 2.47 MB

A TypeScript RPC framework, with runtime type checking and serialization, support both HTTP and WebSocket. It is very suitable for website / APP / games, and absolutely comfortable to full-stack TypeScript developers.

License: MIT License

TypeScript 99.31% JavaScript 0.69%
typescript rpc framework nodejs ajax axios full-stack node runtime-type-checking typescript-serialization protobuf grpc nestjs express backend-framework full-stack-development full-stack-developer serialization-algorithm typescript-rpc-framework server-framework

tsrpc's Introduction

TSRPC

EN / δΈ­ζ–‡

A TypeScript RPC framework with runtime type checking and binary serialization.

Official site: https://tsrpc.cn (English version is on the way)

Features

  • Runtime type checking
  • Binary serialization
  • Pure TypeScript, without any decorater or other language
  • HTTP / WebSocket / and more protocols...
  • Optional backward-compatibility to JSON
  • High performance and reliable, verified by services over 100,000,000 users

Create Full-stack Project

npx create-tsrpc-app@latest

Usage

Define Protocol (Shared)

export interface ReqHello {
  name: string;
}

export interface ResHello {
  reply: string;
}

Implement API (Server)

import { ApiCall } from "tsrpc";

export async function ApiHello(call: ApiCall<ReqHello, ResHello>) {
  call.succ({
    reply: 'Hello, ' + call.req.name
  });
}

Call API (Client)

let ret = await client.callApi('Hello', {
    name: 'World'
});

Examples

https://github.com/k8w/tsrpc-examples

Serialization Algorithm

The best TypeScript serialization algorithm ever. Without any 3rd-party IDL language (like protobuf), it is fully based on TypeScript source file. Define the protocols directly by your code.

This is powered by TSBuffer, which is going to be open-source.

TypeScript has the best type system, with some unique advanced features like union type, intersection type, mapped type, etc.

TSBuffer may be the only serialization algorithm that support them all.

API Reference

See API Reference.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.