Karthik Srivatsa
Karthik Srivatsa

Reputation: 25

For fetching data from server for React frontend should I use websockets or api calls?

I am very new to frontend. I do not exactly know how react frontends work. Assuming I have a frontend written in React that needs to refresh data on the page say every ten seconds, can I achieve that by making api calls to a server every ten seconds or open a websocket with it and make the server push data? These are not notifications! They are just statistical data that needs to be updated on the page in realtime. Please tell me whats a good way to achieve this.

Upvotes: 0

Views: 685

Answers (1)

LoremIpsum
LoremIpsum

Reputation: 4428

Websockets are interesting when you want data to be pushed from your server to your client, i.e. when the client doesn't know when new data will be available. In your case, it seems that simple API calls will be enough.

Upvotes: 1

Related Questions