Quark Engine - Channel selection

In Quark Engine Web Demo app, one could see examples for exposing Java classes through HTTP/s and WebSocket channels. Now, the question is how to use only HTTP/s channel or only WebSocket channel. In this short tutorial we will show how.

Quark Engine contains 2 main endpoint types:

  • io.greenscreens.web.APIServlet - HTTP/s channel
  • io.greenscreens.websocket.WebSocketService - WebSocket channel

APIServlet use Http GET method to return JSON structure describing exposed Java Classes and their methods while Http POST is used to handle API calls from browser.

WebSocketService handle API calls and automatic API registration if both "api" and "service" URL's are the same.

When using only HTTP/s channel, simply do not define WebSocket service inside Java Web App module. And when using WebSocket channel, do not define servlet based on APIServlet class. And that's all what is required on server side. If you want to use them both, sure, no problem also.

From browser side few combinations are possible.

API and service through HTTP/s channel

let url = 'http://localhost/demo/api';
await Engine.init({api: url, service: url}):

API and service through WebSocket channel

let url = 'ws://localhost/demo/socket';
await Engine.init({api: url, service: url});

API through HTTP/s channel and service through WebSocket channel

let api = 'http://localhost/demo/api';
let ws = 'ws://localhost/demo/socket';
await Engine.init({api: api, service: ws});

Which one to use?

Well, we would prefer WebSocket only approach. In a case when there are technical problems as some network security devices might not be configured properly for WebSocket or they are blocking WebSocket for some reason, standard HTTP approach is the only solution.

Main difference is that WebSocket is open active channel, while http/https makes connection handshake every time making reponses a llitle bit slower, and making a litle bit more pressure on the server side.