Prototyping node-sword-interface web service

Tobias Klein <[email protected]>
Newsgroups gmane.comp.literature.sword.devel
Message-ID <[email protected]>
Hi Aaron & all,

so, this whole thread about SWORD over network inspired me to play with 
existing technology a bit.
The goal: Run Ezra Bible App accessing the SWORD modules via a remote 
server instead of locally.

I implemented a small web service API based on node-sword-interface and 
expressjs. See https://github.com/ezra-bible-app/ezra-bible-app-server

Example - 
https://github.com/ezra-bible-app/ezra-bible-app-server/blob/main/routes/module.js

// Delivers the text of a chapter via the url 
/module/<moduleCode>/chaptertext/<bookCode>/<chapterNumber>

router.get('/:moduleCode/chaptertext/:bookCode/:chapter', (req, res) => {
   const moduleCode = req.params.moduleCode;
   const bookCode = req.params.bookCode;
   const chapter = parseInt(req.params.chapter);

   const chapterText = nsi.getChapterText(moduleCode, bookCode, chapter);
   res.json(chapterText);
});

See here for example server deployed on some AWS machine I quickly set 
up. The following URL delivers the KJV text of John 5 as JSON.
http://ec2-13-48-148-192.eu-north-1.compute.amazonaws.com/module/KJV/chaptertext/John/5

Then I made some adjustments in the backend of Ezra Bible App, 
implementing a "switch" in a few methods that normally access a local 
node-sword-interface / SWORD installation.

The respective example section in the Ezra Bible App backend looks like 
this:
https://github.com/ezra-bible-app/ezra-bible-app/blob/web-api/app/backend/ipc/ipc_nsi_handler.js#L243

     this._ipcMain.add('nsi_getChapterText', async (moduleCode, 
bookCode, chapter) => {
       if (!this._useWebApi) {
         return this._nsi.getChapterText(moduleCode, bookCode, chapter);
       } else {
         return await 
this.getFromWebApi(`/module/${moduleCode}/chaptertext/${bookCode}/${chapter}`);
       }
     });

Based on the switch useWebApi (currently just a constant) I can switch 
between the "local version" and the "remote version".
The interface is compatible, because both the local version and the 
remote version pull data from node-sword-interface and that already 
returns JSON as of today.

I ended up with a test version of Ezra Bible App that would load module 
lists and offer the regular browsing capabilities as the normal 
"offline" variant.
The performance in the UI for regular Bible browsing is nearly the same.

The use case that I see is to install a bunch of popular modules on the 
server side for different languages and offer these to the user based on 
quick "online access" right after installing the app.

I am also interested how this behaves when the internet connection is 
slower. I'll report some findings once I have them. It should be easy to 
simulate that now based on the developer tools built into Electron.

Right now this is an experiment. I'll explore a bit more and if this 
turns out useful, I may think about integrating this into Ezra.

Best regards,
Tobias

_______________________________________________
sword-devel mailing list: [email protected]
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.