https://github.com/yujuiting/jtrpc
json rpc server
https://github.com/yujuiting/jtrpc
jsonrpc2 koa nodejs typescript
Last synced: over 1 year ago
JSON representation
json rpc server
- Host: GitHub
- URL: https://github.com/yujuiting/jtrpc
- Owner: yujuiting
- Created: 2018-12-07T09:28:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-08T14:39:47.000Z (over 7 years ago)
- Last Synced: 2025-02-23T09:38:52.784Z (over 1 year ago)
- Topics: jsonrpc2, koa, nodejs, typescript
- Language: TypeScript
- Size: 68.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jtrpc
A json rpc server framework.
## install
```
$ npm install typedi koa koa-bodyparser @jtrpc/core @jtrpc/koa
```
## quick start
```typescript
import { Service } from 'typedi';
import * as Koa from 'koa';
import * as bodyparser from 'koa-bodyparser';
import jtrpc from '@jtrpc/koa';
import { MethodInstance } from '@jtrpc/core';
const app = new Koa();
app.use(bodyparser());
app.use(jtrpc({
methodResolver: method => {
switch (method) {
case 'math.sum': return Sum;
}
},
}));
app.listen(3000, () => console.log('server up'));
@Service('ping')
class Ping extends MethodInstance {
execute() {
return 'pong';
}
validateParameters() {
return true;
}
}
@Service()
class Sum extends MethodInstance {
execute(...values: number[]) {
return values.reduce((acc, curr) => acc + curr, 0);
}
validateParameters(...values: unknown[]) {
return values.every(value => typeof value === 'number');
}
}
```