typed-rpc-client

Client side of typed-rpc, a Typescript library for simplifing communication between front-end and back-end.

Usage no npm install needed!

<script type="module">
  import typedRpcClient from 'https://cdn.skypack.dev/typed-rpc-client';
</script>

README

typed-rpc-client

Client side of typed-rpc, a Typescript library for simplifing communication between front-end and back-end.

Installing

Using npm:

$ npm install typed-rpc-client

Using yarn:

$ yarn add typed-rpc-client

Quick example

// routes.ts
export default interface Routes {
  hello(str: string): string
}

// server.ts
import Routes from "./routes"

import express from "express"
import RPCServer from "typed-rpc-server"

const handler = RPCServer.create<Routes>({
  routes: {
    hello(str: string): string {
      return "Hello " + str
    }
  }
})

const app = express()
app.use("/rpc", handler)
app.listen(8080)

// client.ts
import Routes from "./routes"

import RPCClient from "typed-rpc-client"

const rpc = RPCClient.create<Routes>({ url: "http://localhost:8080/rpc" })

rpc.hello("world").then((res) => {
  console.log(res) // Hello world
})

Documentation

Coming soon