Skip to content

Commit 62527d6

Browse files
authored
Update README.md
1 parent 617a7ae commit 62527d6

File tree

1 file changed

+18
-45
lines changed

1 file changed

+18
-45
lines changed

README.md

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,82 +19,55 @@ pip install git+https://github.com/NF-coder/SimpleRPC.git
1919

2020
server.py
2121
```python
22-
from SimpleRPC import GrpcServer
22+
from simple_rpc.v2.server import GrpcServerV2
2323
from pydantic import BaseModel
24-
import asyncio
2524

2625
class RequestModel(BaseModel):
27-
num1: int
26+
pass
2827

2928
class ResponceModel(BaseModel):
3029
num2: int
3130
num4: int
3231

33-
app = GrpcServer(
34-
proto_filename = "proto.proto"
35-
)
32+
app = GrpcServerV2()
3633

37-
class Server:
38-
@app.grpc_method(inp_model=RequestModel, out_model=ResponceModel, out_proto_name="ResponceMsg")
39-
async def Method(self, num1) -> ResponceModel:
34+
class Server:
35+
@app.grpc_method()
36+
async def example_method(self, request: RequestModel) -> ResponceModel:
4037
return ResponceModel(
41-
num2 = num1*2,
42-
num4 = 99
38+
num2 = 3,
39+
num4 = 1
4340
)
4441

4542
app.configure_service(
46-
proto_service_name="Example",
47-
cls = Server(),
48-
port=50055
43+
cls=Server(),
44+
port=50051
4945
)
5046
app.run()
5147
```
5248

5349
client.py
5450
```python
5551
from pydantic import BaseModel
56-
from SimpleRPC import GrpcClient
52+
from simple_rpc.v2.client import GrpcClientV2
5753
import asyncio
5854

59-
class ResponceModel(BaseModel):
60-
num2: int
61-
num4: int
62-
63-
cli = GrpcClient(
64-
port=50055
55+
client = GrpcClientV2(
56+
port=50051
6557
)
66-
command = cli.configure_command(
67-
struct_name="RequestMsg",
68-
func_name="Method",
69-
service_name="Example",
70-
responce_validation_model=ResponceModel
58+
command = client.configure_command(
59+
functionName="example_method",
60+
className="Server"
7161
)
7262

63+
7364
async def run():
7465
print(
75-
await command(num1 = 1)
66+
await command()
7667
)
7768

7869
if __name__ == "__main__":
7970
asyncio.run(
8071
run()
8172
)
8273
```
83-
84-
proto.proto
85-
```protobuf
86-
syntax = "proto3";
87-
88-
service Example {
89-
rpc Method(RequestMsg) returns (ResponceMsg) {}
90-
}
91-
92-
message RequestMsg {
93-
int32 num1 = 1;
94-
}
95-
96-
message ResponceMsg {
97-
int32 num2 = 1;
98-
int32 num4 = 2;
99-
}
100-
```

0 commit comments

Comments
 (0)