So I am planning on building a Single Page Application. In that application, there will be a lot of API calls, and very frequent from what we expect.
So we were thinking of foregoing API calls and replacing it with WebSockets totally. So how we're planning to make this work is as follows:
- We designate a special code(or socket message type) for each resouce the client can request.
- Client connects to the server via a websocket.
- For each resource/data the client wants, it send a message to the server with the predefined code.
- Server processes the request and sends the response back to the client.
- Client and server keep the connection open, and any future requests are communicated over the same socket.
We expect to reduce overhead and latency with this approach, but is that a right assumption? Also, what could be the pitfalls of using this mechanism?