typed-rpc-client
TypeScript icon, indicating that this package has built-in type declarations

0.1.10 • Public • Published

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

Package Sidebar

Install

npm i typed-rpc-client

Weekly Downloads

0

Version

0.1.10

License

MIT

Unpacked Size

21.1 kB

Total Files

12

Last publish

Collaborators

  • klo112358