0xtuytuy
0xtuytuy

Reputation: 1654

API design, mix sockets and REST API point?

This is not a straight question but rather a call for opinion.

I am in the process of designing an API using NodeJS and I would really need sockets for some applications but not for all.

Is it good practise to mix both Socket.IO and normal Express REST API point ? what are your opinions ? What would be the advantages and disadvantages to do the mix up ?

Upvotes: 1

Views: 1442

Answers (1)

Phil Sturgeon
Phil Sturgeon

Reputation: 30766

It's entirely fine to use HTTP endpoints and websockets, as until HTTP/2 came along, the only solutions to getting updates back from background processes were:

  1. Polling
  2. Callbacks (Web Hooks)

Neither of these are ideal, but luckily HTTP/2 with Server Push means you can stream down updates as they come, making WebSockets not quite so required.

That said if you have other use cases for WebSockets then absolutely, off you go!

Relevant: https://www.infoq.com/articles/websocket-and-http2-coexist

Upvotes: 2

Related Questions