https://github.com/morglod/morglod-rpc
https://github.com/morglod/morglod-rpc
rpc rpc-framework typescript
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/morglod/morglod-rpc
- Owner: Morglod
- Created: 2018-05-25T13:38:37.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-23T01:45:48.000Z (over 7 years ago)
- Last Synced: 2025-02-25T02:17:42.042Z (over 1 year ago)
- Topics: rpc, rpc-framework, typescript
- Language: TypeScript
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# morglod-rpc
Simple OOP rpc with remote callback support.
!! Install by `--save-exact`, coz still in development.
## Example
Server:
```ts
const httpServer = http.createServer();
httpServer.listen(PORT);
const server = SocketIOServer(httpServer);
server.on('connection', socket => {
const transport = new SocketIOTransport(socket);
// Provide RPC methods to SocketIO connection.
new Api({
methods: {
// `resolve` is remote callback!
readFile: (path: string, resolve: (data: string) => void) => {
fs.readFile(path, 'utf8', (err, data) => {
if (err) return;
resolve(data);
});
})
}
}, transport);
});
```
Protocol:
```ts
type ApiDef = {
readFile: (path: string, resolve: (data: string) => void) => void,
};
```
Client:
```ts
const socket = SocketIO.connect(httpBind);
const transport = new SocketIOTransport(socket);
const api = new Api({}, transport);
api.callMethod('readFile', 'file.txt', (fileData: string) => {
console.log('yeyy!', fileData);
});
```
# TODO
Add middlewares and pre-call hooks