Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
derbenoo committed Jan 7, 2019
1 parent d89736c commit ecacd27
Show file tree
Hide file tree
Showing 22 changed files with 325 additions and 881 deletions.
62 changes: 53 additions & 9 deletions README.md
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 added docs/.nojekyll
Empty file.
2 changes: 1 addition & 1 deletion docs/assets/js/search.js

Large diffs are not rendered by default.

506 changes: 0 additions & 506 deletions docs/classes/_endpoints_pm2_.pm2endpoint.html

This file was deleted.

103 changes: 75 additions & 28 deletions docs/classes/_rpc_endpoint_.rpcendpoint.html

Large diffs are not rendered by default.

101 changes: 82 additions & 19 deletions docs/classes/_rpc_server_.rpcserver.html

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions docs/globals.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>pm2-rpc-api</title>
<title>rpc-automagic</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
Expand All @@ -22,7 +22,7 @@
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">pm2-rpc-api</a>
<a href="index.html" class="title">rpc-automagic</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
Expand Down Expand Up @@ -56,7 +56,7 @@
<a href="globals.html">Globals</a>
</li>
</ul>
<h1> pm2-rpc-api</h1>
<h1> rpc-automagic</h1>
</div>
</div>
</header>
Expand All @@ -71,7 +71,6 @@ <h2>Index</h2>
<h3>External modules</h3>
<ul class="tsd-index-list">
<li class="tsd-kind-external-module"><a href="modules/_authentication_.html" class="tsd-kind-icon">"authentication"</a></li>
<li class="tsd-kind-external-module"><a href="modules/_endpoints_pm2_.html" class="tsd-kind-icon">"endpoints/pm2"</a></li>
<li class="tsd-kind-external-module"><a href="modules/_interfaces_.html" class="tsd-kind-icon">"interfaces"</a></li>
<li class="tsd-kind-external-module"><a href="modules/_rpc_endpoint_.html" class="tsd-kind-icon">"rpc-<wbr>endpoint"</a></li>
<li class="tsd-kind-external-module"><a href="modules/_rpc_schema_.html" class="tsd-kind-icon">"rpc-<wbr>schema"</a></li>
Expand All @@ -91,9 +90,6 @@ <h3>External modules</h3>
<li class=" tsd-kind-external-module">
<a href="modules/_authentication_.html">"authentication"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_endpoints_pm2_.html">"endpoints/pm2"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_interfaces_.html">"interfaces"</a>
</li>
Expand Down
52 changes: 44 additions & 8 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>pm2-rpc-api</title>
<title>rpc-automagic</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
Expand All @@ -22,7 +22,7 @@
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">pm2-rpc-api</a>
<a href="index.html" class="title">rpc-automagic</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
Expand Down Expand Up @@ -56,16 +56,55 @@
<a href="globals.html">Globals</a>
</li>
</ul>
<h1> pm2-rpc-api</h1>
<h1> rpc-automagic</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<div class="tsd-panel tsd-typography">
<h1 id="simple-node-rpc-server">Simple Node RPC Server</h1>
<p>Simple HTTP JSON-RPC API for administrative tasks on PM2 managed node containers</p>
<h1 id="automagic-rpc-api-generation">Automagic RPC-API Generation</h1>
<p>Automagically create HTTP JSON-RPC 2.0 endpoints for any node module!</p>
<h2 id="installation">Installation</h2>
<p>Installation is straight forward with npm:</p>
<pre><code>npm <span class="hljs-selector-tag">i</span> rpc-automagic</code></pre><h2 id="example">Example</h2>
<ol>
<li>Create a simple RPC server allowing the execution of shell commands using the <code>execa</code> module:
<code>`</code>ts
import * as execa from &#39;execa&#39;;
import { RpcServer } from &#39;rpc-automagic&#39;;</li>
</ol>
<p>const server = new RpcServer();
server.addEndpoint(&#39;/execa&#39;, execa);
server.start();</p>
<pre><code>
<span class="hljs-number">2.</span> Send <span class="hljs-keyword">a</span> POST request <span class="hljs-built_in">to</span> <span class="hljs-keyword">http</span>://localhost:<span class="hljs-number">1337</span>/execa</code></pre><p>{
&quot;jsonrpc&quot;: &quot;2.0&quot;,
&quot;id&quot;: 1,
&quot;method&quot;: &quot;shell&quot;,
&quot;params&quot;: [
&quot;whoami&quot;
]
}</p>
<pre><code>
<span class="hljs-number">3.</span> <span class="hljs-type">Parse</span> the response <span class="hljs-class"><span class="hljs-keyword">object</span></span>:</code></pre><p>{
&quot;jsonrpc&quot;: &quot;2.0&quot;,
&quot;id&quot;: 1,
&quot;result&quot;: {
&quot;stdout&quot;: &quot;root&quot;,
&quot;stderr&quot;: &quot;&quot;,
&quot;code&quot;: 0,
&quot;failed&quot;: false,
&quot;killed&quot;: false,
&quot;signal&quot;: null,
&quot;cmd&quot;: &quot;/bin/sh -c whoami&quot;,
&quot;timedOut&quot;: false
}
}
<code>`</code></p>
<h2 id="api-documentation">API Documentation</h2>
<p>The API documentation can be found here: <a href="https://decentro-gmbh.github.io/rpc-automagic/">https://decentro-gmbh.github.io/rpc-automagic/</a></p>
</div>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
Expand All @@ -77,9 +116,6 @@ <h1 id="simple-node-rpc-server">Simple Node RPC Server</h1>
<li class=" tsd-kind-external-module">
<a href="modules/_authentication_.html">"authentication"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_endpoints_pm2_.html">"endpoints/pm2"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_interfaces_.html">"interfaces"</a>
</li>
Expand Down
13 changes: 5 additions & 8 deletions docs/interfaces/_interfaces_.ilogger.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>ILogger | pm2-rpc-api</title>
<title>ILogger | rpc-automagic</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../assets/css/main.css">
Expand All @@ -22,7 +22,7 @@
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="../index.html" class="title">pm2-rpc-api</a>
<a href="../index.html" class="title">rpc-automagic</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
Expand Down Expand Up @@ -107,7 +107,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> err</h3>
<div class="tsd-signature tsd-kind-icon">err<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/decentro-gmbh/pm2-rpc-api/blob/44efc2f/src/interfaces.ts#L26">interfaces.ts:26</a></li>
<li>Defined in <a href="https://github.com/decentro-gmbh/pm2-rpc-api/blob/d89736c/src/interfaces.ts#L26">interfaces.ts:26</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -122,7 +122,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> info</h3>
<div class="tsd-signature tsd-kind-icon">info<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/decentro-gmbh/pm2-rpc-api/blob/44efc2f/src/interfaces.ts#L22">interfaces.ts:22</a></li>
<li>Defined in <a href="https://github.com/decentro-gmbh/pm2-rpc-api/blob/d89736c/src/interfaces.ts#L22">interfaces.ts:22</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -137,7 +137,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> warn</h3>
<div class="tsd-signature tsd-kind-icon">warn<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Function</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/decentro-gmbh/pm2-rpc-api/blob/44efc2f/src/interfaces.ts#L24">interfaces.ts:24</a></li>
<li>Defined in <a href="https://github.com/decentro-gmbh/pm2-rpc-api/blob/d89736c/src/interfaces.ts#L24">interfaces.ts:24</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -157,9 +157,6 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> warn</h3>
<li class=" tsd-kind-external-module">
<a href="../modules/_authentication_.html">"authentication"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="../modules/_endpoints_pm2_.html">"endpoints/pm2"</a>
</li>
<li class="current tsd-kind-external-module">
<a href="../modules/_interfaces_.html">"interfaces"</a>
</li>
Expand Down
13 changes: 5 additions & 8 deletions docs/interfaces/_interfaces_.irpcerror.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>IRpcError | pm2-rpc-api</title>
<title>IRpcError | rpc-automagic</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../assets/css/main.css">
Expand All @@ -22,7 +22,7 @@
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="../index.html" class="title">pm2-rpc-api</a>
<a href="../index.html" class="title">rpc-automagic</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
Expand Down Expand Up @@ -107,7 +107,7 @@ <h3>code</h3>
<div class="tsd-signature tsd-kind-icon">code<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/decentro-gmbh/pm2-rpc-api/blob/44efc2f/src/interfaces.ts#L62">interfaces.ts:62</a></li>
<li>Defined in <a href="https://github.com/decentro-gmbh/pm2-rpc-api/blob/d89736c/src/interfaces.ts#L62">interfaces.ts:62</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -122,7 +122,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> data</h3>
<div class="tsd-signature tsd-kind-icon">data<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">any</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/decentro-gmbh/pm2-rpc-api/blob/44efc2f/src/interfaces.ts#L66">interfaces.ts:66</a></li>
<li>Defined in <a href="https://github.com/decentro-gmbh/pm2-rpc-api/blob/d89736c/src/interfaces.ts#L66">interfaces.ts:66</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -137,7 +137,7 @@ <h3>message</h3>
<div class="tsd-signature tsd-kind-icon">message<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/decentro-gmbh/pm2-rpc-api/blob/44efc2f/src/interfaces.ts#L64">interfaces.ts:64</a></li>
<li>Defined in <a href="https://github.com/decentro-gmbh/pm2-rpc-api/blob/d89736c/src/interfaces.ts#L64">interfaces.ts:64</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -157,9 +157,6 @@ <h3>message</h3>
<li class=" tsd-kind-external-module">
<a href="../modules/_authentication_.html">"authentication"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="../modules/_endpoints_pm2_.html">"endpoints/pm2"</a>
</li>
<li class="current tsd-kind-external-module">
<a href="../modules/_interfaces_.html">"interfaces"</a>
</li>
Expand Down
7 changes: 2 additions & 5 deletions docs/interfaces/_interfaces_.irpcmodule.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>IRpcModule | pm2-rpc-api</title>
<title>IRpcModule | rpc-automagic</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../assets/css/main.css">
Expand All @@ -22,7 +22,7 @@
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="../index.html" class="title">pm2-rpc-api</a>
<a href="../index.html" class="title">rpc-automagic</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
Expand Down Expand Up @@ -103,9 +103,6 @@ <h3 class="tsd-before-signature">Indexable</h3>
<li class=" tsd-kind-external-module">
<a href="../modules/_authentication_.html">"authentication"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="../modules/_endpoints_pm2_.html">"endpoints/pm2"</a>
</li>
<li class="current tsd-kind-external-module">
<a href="../modules/_interfaces_.html">"interfaces"</a>
</li>
Expand Down
Loading

0 comments on commit ecacd27

Please sign in to comment.