I have a REST API that implements server-side pagination returning the following data:
{
items: [
{
id: 1,
name: 1
},
{
id: 2,
name: 2
}
],
nextToken: <some-hash-key> // cursor-based
}
How should the client application refresh the list if the resource gets updated (client isn't aware of the update, so this is a pull model)? I have some ideas:
- fetch all resources at a regular interval (like every 10 seconds)
- maintain a session ID that rotates every N minutes. When a new session is created, fetch all resources
Both approaches are fundamentally the same idea. The first approach is more costly but allows more real-time updates. The second approach is based on session ID which I think is more idiomatic, but no real-time updates. Is there any other approach?
CodePudding user response:
REST APIs are not designed for real time updates; for that you need sockets.
CodePudding user response:
It is not scalable to update every single update to client-side in realtime, so it has to be an updation at regular interval. The duration/interval time could be decided based on facts on the table.
You can use simple integration like https://socket.io
and a cron like architecture to broadcast updates in regular intervals.