Home > Back-end >  Best practices for building a chat app? (REST vs Websockets)
Best practices for building a chat app? (REST vs Websockets)

Time:02-14

As the title suggests, I'm building a simple chat app in Node/Express React, and I'm using socket.io to get real time updates.

However, other than the chatting itself, rest of my app is very basic (registering, signing in, creating rooms etc), and while it's definitely doable to make all those requests just socket emits, it feels like bit of an overkill.

So I was thinking of creating a regular REST API for that stuff and outsourcing it into a separate file, then creating another file just for the chatting function itself, where I'd use socket.io, but I'm afraid that it may seem a bit unprofessional, or leave an impression that I don't know how to use sockets well enough.

Key point: When finished, this app will be posted to my portfolio, so I'm not very concerned about what just "can work", but rather what's the best and cleanest way to do it? Should I switch everything to sockets and use them even for basic fetching of lists and stuff? Or is it better practice to mix the two, and use REST for, well, the rest?

CodePudding user response:

In my experience, To mix the two is the best way to do that. I did that in many projects and it worked well. I surely think that modularity is the best way to make code clean and qualified. So, to use both of regular REST API and websocket is more professional. Thank you.

  • Related