Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xujif/ts-json-rpc
https://github.com/xujif/ts-json-rpc
Last synced: 17 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/xujif/ts-json-rpc
- Owner: xujif
- Created: 2018-04-23T05:54:47.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-04T07:05:22.000Z (over 6 years ago)
- Last Synced: 2024-11-25T13:06:57.969Z (28 days ago)
- Language: TypeScript
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
### Client with http Trasport
```typescript
import { createHttpRpcClient } from 'json-rpc2.0-node'
const client = createHttpRpcClient('http://endpoint',{Authorization:"token or other headers, or other http header"})
const res = await client.invoke('method','param1','param2')
client.notify('method','param1','param2')// or cast to an interface
const t:T = client.as()
t.method('param1','param2')```
### Client with custom Trasport
```typescript
// implement the transport interface
// export interface Transport {
// (payload: string): Promise
// }import { Client,Trasport } from 'json-rpc2.0-node'
function Mytransport(json:string){
return Promise.resolve(/*json respose*/)
}const client = new Client(Mytransport)
```
### Server
```typescript
import { Server } from 'json-rpc2.0-node'
const server = new Server()
server.expose('hello', () => 'hello world!')
const jsonbody = `
{
"id":10,
"method":"hello",
"jsonrpc":"2.0"
}
`
const jsonrpcResponse = await server.handle(jsonbody)
// send your response back to client```
see more help in src/tests