Vuetable-2: Is there any good way to refresh the api call automatically Periodically?

Created on 23 May 2017  路  6Comments  路  Source: ratiw/vuetable-2

I want to make table refresh automatically with latest api uri request and return data.(actually refresh in every 5 sec)
I think if i use last api requst uri and setInterval function on mounted() method, it will be working.
I wonder,

  • Is it the best way to make auto priodically call?
  • how can i get the last api request uri?
  • any problem with that logic?
  • best practice

thanks

Most helpful comment

If it's an option, I would use a DB such as MongoDB, PubNub or RethinkDB, and have it update the contents of the table in realtime. You could then save the last time the order was updated (epoch or something like that), and you could check on that value in an interval. That's just one way to do it.
Another way could be to use socket.io or something like it, and whenever the data changes, you get notified and update the table. Then you could have the interval running on the client checking for any order older than whatever time period you designate.

All 6 comments

@dongwooklee9 You should avoid trying to that because some well known API services usually have rate limit restriction on calling the API like that (especially every 5 sec). Instead, you should always design the app to request the data only when it is needed.

  • There is no best way, but if you have to do it you can use setTimeout to call refresh method in Vuetable.
  • It's the same one that you set to `api-url' property. Are you planning to use more than one API with the same Vuetable?
  • Avoid it if you can.
  • Don't believe anyone, try it and consider if it works for you.

I agree with @ratiw unless you manage the API serverside as well, so you know what the rate limits are ;-)

Thanks for your detailed answers.
Explaining more about my project, It's like a Uber-eat, It's to get the order every second and link the driver with the order automatically in normal situation. I want to use the table on admin page monitoring the order-delivery, to find out some stuck order and solve it on the table manually
I'm planning to use this table to check the orders
I can modify the setTimeout to 5sec, 10sec, 30sec.
I will try it and share the result!
Please feel free any comments or advice
Thanks you @denjaland and @ratiw!

  • Also I can set the servers limits manually

If it's an option, I would use a DB such as MongoDB, PubNub or RethinkDB, and have it update the contents of the table in realtime. You could then save the last time the order was updated (epoch or something like that), and you could check on that value in an interval. That's just one way to do it.
Another way could be to use socket.io or something like it, and whenever the data changes, you get notified and update the table. Then you could have the interval running on the client checking for any order older than whatever time period you designate.

Anyone try/think of using CouchDB/PouchDB in this context? I am using it on another project. For example and event is fired with DB updates at which point you can refresh the table.

I am just now looking at wiring up vuetable with PouchDB api endpoint.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hjJunior picture hjJunior  路  3Comments

mannyyang picture mannyyang  路  3Comments

kawamataryo picture kawamataryo  路  3Comments

coderabsolute picture coderabsolute  路  4Comments

arthurvasconcelos picture arthurvasconcelos  路  3Comments