-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
325 additions
and
881 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,62 @@ | ||
# Automagic RPC-API Generation | ||
# RPC Automagic | ||
|
||
Automagically create HTTP JSON-RPC 2.0 endpoints for any node module! | ||
[![](https://img.shields.io/badge/TypeScript-v3-blue.svg?style=flat)](https://github.com/decentro-gmbh/rpc-automagic/blob/master/package.json | ||
) [![](https://img.shields.io/npm/v/rpc-automagic.svg)](https://www.npmjs.com/package/rpc-automagic | ||
) [![](https://img.shields.io/snyk/vulnerabilities/npm/rpc-automagic.svg)](https://www.npmjs.com/package/rpc-automagic | ||
) [![](https://img.shields.io/github/license/decentro-gmbh/rpc-automagic.svg?style=flat)](https://github.com/decentro-gmbh/rpc-automagic/blob/master/LICENSE) | ||
|
||
Automagically create HTTP [JSON-RPC 2.0](https://www.jsonrpc.org/specification) endpoints for any node module! | ||
|
||
## Installation | ||
|
||
Installation is straight forward with npm: | ||
``` | ||
npm i rpc-automagic | ||
``` | ||
|
||
## Example | ||
|
||
1. Create a simple RPC server allowing the execution of shell commands using the `execa` module: | ||
|
||
```ts | ||
import * as execa from 'execa'; | ||
import { RpcServer } from 'rpc-automagic'; | ||
const execa = require('execa'); | ||
const { RpcServer } = require('rpc-automagic'); | ||
|
||
const server = new RpcServer(); | ||
server.addEndpoint('/execa', execa); | ||
server.start(); | ||
``` | ||
|
||
server.addEndpoint({ | ||
'/execa': execa, | ||
}) | ||
2. Send a POST request to http://localhost:1337/execa | ||
``` | ||
{ | ||
"jsonrpc": "2.0", | ||
"id": 1, | ||
"method": "shell", | ||
"params": [ | ||
"whoami" | ||
] | ||
} | ||
``` | ||
|
||
server.start(); | ||
``` | ||
3. Parse the response object: | ||
``` | ||
{ | ||
"jsonrpc": "2.0", | ||
"id": 1, | ||
"result": { | ||
"stdout": "root", | ||
"stderr": "", | ||
"code": 0, | ||
"failed": false, | ||
"killed": false, | ||
"signal": null, | ||
"cmd": "/bin/sh -c whoami", | ||
"timedOut": false | ||
} | ||
} | ||
``` | ||
|
||
## API Documentation | ||
|
||
The API documentation can be found here: https://decentro-gmbh.github.io/rpc-automagic/ |
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.