@msaki/jsonrpc 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
## Usage
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
### RPC Server
|
|
6
|
+
|
|
7
|
+
```ts
|
|
6
8
|
import { JsonRpcServer } from "@msaki/jsonrpc";
|
|
7
9
|
|
|
8
10
|
const server = new JsonRpcServer()
|
|
@@ -27,3 +29,25 @@ Bun.serve({
|
|
|
27
29
|
|
|
28
30
|
console.log("JSON-RPC sever on http://localhost:4444")
|
|
29
31
|
```
|
|
32
|
+
|
|
33
|
+
### PRC Client
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { JsonRpcClient } from "@msaki/jsonrpc";
|
|
37
|
+
import type {
|
|
38
|
+
JsonRpcRequest,
|
|
39
|
+
JsonRpcResponse
|
|
40
|
+
} from "@msaki/jsonrpc";
|
|
41
|
+
|
|
42
|
+
const url = "http://localhost:4444";
|
|
43
|
+
|
|
44
|
+
const client = new JsonRpcClient(async (req: JsonRpcRequest) => {
|
|
45
|
+
const res = await fetch(url, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: { "Content-Type": "application/json" },
|
|
48
|
+
body: JSON.stringify(req)
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return (await res.json()) as JsonRpcResponse
|
|
52
|
+
});
|
|
53
|
+
```
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@msaki/jsonrpc",
|
|
3
3
|
"author": "Meek Msaki",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/mmsaki/libs
|
|
11
|
+
"url": "git+https://github.com/mmsaki/libs.git",
|
|
12
12
|
"directory": "packages/jsonrpc"
|
|
13
13
|
},
|
|
14
14
|
"publishConfig": {
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
"lint": "tsc"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@changesets/cli": "^2.29.8",
|
|
25
24
|
"@types/bun": "latest",
|
|
26
25
|
"tsup": "^8.5.1"
|
|
27
26
|
},
|