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

0.0.8 • Public • Published

说明

用于远程方法调用 如果RpcClient需要支持表达式解析 需要vweb-core 版本大于3.0.19

示例

声明一个rpc服务示例

配置文件

{
    server: {
        port: 8001 // 默认端口是8000
    }
}

rpc服务类

import {RpcServer, RpcEndpoint} from "vweb-rpc";

@RpcServer
export default class TestRpcServer {

    @RpcEndpoint('test/add')
    test(a, b) {
        return a + b
    }
}

调用rpc服务示例

{
    client: {
        rpcServer:{
             port: 8000,
             host: '127.0.0.1'
         }
    }
}
import {RpcClient, RpcEndpoint} from "vweb-rpc";

@RpcClient('rpcServer') // 对应配置文件里 或者直接写 ip:port 形式
export default class TestRpcClient {

    /**
     * @param {number} a
     * @param {number} b
     * @return number
     */
    @RpcEndpoint('test/add') // 对应rpc服务声明的endpoint
    add(a, b) {
        // 不需要写实现
        return void 0
    }
}

// 在vweb环境下调用 
let resp = await this.testRpcClient.add(1, 2)
console.log(resp)

Readme

Keywords

none

Package Sidebar

Install

npm i vweb-rpc

Weekly Downloads

0

Version

0.0.8

License

ISC

Unpacked Size

76.8 kB

Total Files

29

Last publish

Collaborators

  • xiye