How should the structure of external API calls in an electron application be designed?

In this scenario, my renderer process' goal would be to make an HTTP request to an external web server and receive responses. My question is: which options below would be more secure, give a future developer less headache in terms of the development process, and also be better as a general design approach (whether in case of general software or electron specifically)? Option 1: Currently, from the main process, I am using utilityProcess to create the express web server (using the file path as a custom module in a fork call) as a child process. Using MessageChannelMain (which is similar to Channel Messaging API), I can communicate with the child process. My renderer process will be initiating the request-response cycle and after the first channel with the ipcRenderer and ipcMain methods between renderer and main, there would be a second channel communication between main and the child process. Finally, another trip from child process to main to renderer occurs. Option 2: We would eliminate the child process web server, and use ClientRequest while trying to create a web server in the main process itself. Option 3: We would only use the renderer process to make API calls and connect to the external server directly.

May 15, 2025 - 13:46
 0

In this scenario, my renderer process' goal would be to make an HTTP request to an external web server and receive responses.

My question is: which options below would be more secure, give a future developer less headache in terms of the development process, and also be better as a general design approach (whether in case of general software or electron specifically)?

Option 1:

Currently, from the main process, I am using utilityProcess to create the express web server (using the file path as a custom module in a fork call) as a child process. Using MessageChannelMain (which is similar to Channel Messaging API), I can communicate with the child process.

My renderer process will be initiating the request-response cycle and after the first channel with the ipcRenderer and ipcMain methods between renderer and main, there would be a second channel communication between main and the child process. Finally, another trip from child process to main to renderer occurs.

Option 2:

We would eliminate the child process web server, and use ClientRequest while trying to create a web server in the main process itself.

Option 3:

We would only use the renderer process to make API calls and connect to the external server directly.