I have an application that gets data from RESTful api but I want to know how I can refresh data without reloading the page?
Should I write an observer that checks data each 2min for example? but how can I make that real-time (isn't it bad to send too much requests?)
Your API could use SSE (Server Sent Event). It's an open connection that keeps sending data over.
I don't know about Angular or RxJS, but there is EventSource:
const client = new EventSource('/endpoint')
client.onmessage = ev => {
console.log(ev.data)
}
You can also use the fetch response body .getReader() and work with the readable stream.
Nicolás Parada
Web Developer
Atul Sharma
Full Stack Developer | Cloud Native Applications
Use
web-sockets.. So, that the client doesn't needs to worry about the changes in data at server end. The server will auto-push the changes to client whenever their is any change.Meteorhas such a world class implementation of same functionality out of the box.There are number web-socket modules for Angular . github.com/AngularClass/angular-websocket . On server-end web-sockets are supported by almost all languages natively.