1

I am redeveloping an application with the aim of going along with the more modern techniques. That is how I came across Socket.io, which I integrated with express.js.

I implemented live searching with datatables using socket.io for the filtering & fetching part. Users then can click on individual records and go to a page where they can perform CRUD-operations on these data.

I'm still not sure about how I'm going to implement authentication. What are the pros and cons of using WebSockets vs HTTP for authentication?

Socket.io provides a feature falling back to HTTP if a browser doesn't support WebSockets. So I still do have to implement authentication with HTTP headers/cookies etc. to garantee that all users can use this application, if I am right?

Can WebSockets serve all the needs of an application like I described above and therefore fully replace AJAX calls when my webpage has already opened?

I often see that sockets are used when there is a need for real-time updates, like in a chat app. But does this protocol also fit for RESTful operations in not chat-like apps?

I have two options:

  • Implement authentication with HTTP and then when a user is authenticated WebSockets are open for communication.

  • Implement authentication with WebSockets.

The first option is mixing two protocols in one application and that is something express.js provides. But is this a good approach?

Thanks in advance,

Mike

Maikkeyy
  • 191
  • 1
  • 1
  • 6
  • 3
    No socket.io cannot fully replace http. The browser is going to make an http request when you type in an url. No way to use socket.io for that. Heck, a socket.io connection event starts with an http request so http is required to even get a socket.io connection. If you mean "Can you replace Ajax calls from an already open web page with requests sent over a socket.io connection?", then that would be a more useful question and perhaps you should edit your question to reflect that. – jfriend00 Mar 12 '18 at 00:37
  • Yes, you can successfully do "JSON RPC over Websockets" and drop the HTTP semantics altogether. There are 2 catches: The Browsers tend to like HTTP more, and HTTP based API's are more popular as public facing endpoints. – S.D. Mar 12 '18 at 04:58

0 Answers0