I am creating an application(Nuxtjs
) and am having troubles determining a good approach for sending data to the API(expressjs
) and retrieving real-time updates. It seems that i can create "bi-di" connections with both protocals [Server Sent Events(SSE
) and Axios
or Websocket(WS
)].
Both technologies work with most of the browsers, so i do not see a need to add additional libraries such as socket.io
- For those individuals that do not have a current browser (too bad).
The application is based on user input of form data/clicks. Other users are then notified/updated with the information. At which point, the user can respond and the chain goes on(Basic chat like flow some information will be exchanged quickly while some may not or ever).
In my experience, the user flow would rely more heavily on listening for changes than actually changing the data - hence why i'm considering SSE
. Unfortunately, both protocols have their flaws.
Websockets:
WS
to get/post information as such it doesn't make sense to upgrade a basic http connection at the additional server expense. Therefore another method other than WS
will be required(Axios/SSR
). Example: Checking to see if a user name exists
WS
for operating properlyexpress-ws
makes sockets easy on the API endServer Sent Events
WS
WS
node-spdy
within the expressjs
API - This may also be a good implementation for WS
due to multiplexinghttp2
and emit the SSE
s(Ugly code as well - so functions will be made)TLDR
The application will be more "feed" orientated with occasional posting(which can be handled by Axios
). However, users will be listening to multiple "feeds" and the HTTP limitations will be a problem. I do not know what the solution would be because SSE
seem like the better option as i do not need to continually handshake. If this handshake is truly inconsequential(which from everything i have read isn't the case) than WS
is likely a better alternative. Unfortunately, there is soooo much conflicting information regarding the two.
Thoughts?
SSE, Web Sockets, and normal HTTP requests (via AJAX or Fetch API) are all different tools for different jobs.
From your description, it sounds like either SSE or Web Sockets would be appropriate for your use case. I'd probably lean towards SSE, while sending the random API calls from the client with normal HTTP requests.
I do not know what the solution would be because SSE seem like the better option as i do not need to continually handshake. If this handshake is truly inconsequential(which from everything i have read isn't the case) than WS is likely a better alternative.
Keep in mind that you can simply configure your server with HTTP keep-alive, making this point moot.