tunel

0.5.1 • Public • Published
  ___                 /
    _-_-  _/\____    / __\\__
 _-_-__  / ,-. -|   /  -  ,-.`-.
    _-_- `( o )--  /  --( o )-'
           `-'    /      `-'
tunel (n): RESTful message tunneling over IPC.

Quick Example

Here’s the code for Electron’s main thread:

//
// 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):

//
// 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();

Package Sidebar

Install

npm i tunel

Weekly Downloads

16

Version

0.5.1

License

MIT

Unpacked Size

13.4 kB

Total Files

10

Last publish

Collaborators

  • volkan