https://github.com/zerotohero-dev/tunel
Tunel: Tunnels REST-like requests over IPC/Channels.
https://github.com/zerotohero-dev/tunel
Last synced: 8 months ago
JSON representation
Tunel: Tunnels REST-like requests over IPC/Channels.
- Host: GitHub
- URL: https://github.com/zerotohero-dev/tunel
- Owner: zerotohero-dev
- License: other
- Created: 2018-11-13T02:36:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-26T21:16:17.000Z (over 7 years ago)
- Last Synced: 2025-10-06T11:36:29.972Z (8 months ago)
- Language: JavaScript
- Size: 25.4 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
```text
___ /
_-_- _/\____ / __\\__
_-_-__ / ,-. -| / - ,-.`-.
_-_- `( o )-- / --( o )-'
`-' / `-'
tunel (n): RESTful message tunneling over IPC.
```
## Quick Example
Here’s the code for Electron’s **main thread**:
```javascript
//
// Main Thread
//
const electron = require('electron');
const channel = electron.ipcMain;
const { app, registerChannel } = require('tunel/server');
registerChannel(channel);
// `app` API is similar to `express.js`
app.get('/api/v1/profile', async req => {
// You can access req.body, req.params…
void req;
// Unlike express, there is no `res` object.
// As soon as you return from the function, you’ll relay
// a response back.
// So, returning a JSON `json`, is similar to `res.send(json)`.
return {
userName: 'robert',
fullName: 'Robert Denir Ona'
};
});
```
Here’s the cod for Electron’s **renderer thread** (_i.e., the browser_):
```javascript
//
// Renderer Thread
//
import request from 'tunel';
const doFetch = async () => {
// `request` API is similar to `axios`.
const response = await request({
method: 'GET',
url: '/api/v1/profile',
data: { some: 'payload' },
headers: {
'Content-Type': 'application/json'
}
});
// Will log
// `{ status: 200, data: { userName: 'robert',
// fullName: 'Robert Denir Ona' }}`
console.log(response);
};
doFetch();
```