简体   繁体   English

如何模拟流式API?

[英]How to emulate a streaming API?

I need to maintain a almost real-time access to an API(so that the program gets notified immediately when the API response changes). 我需要维护对API的几乎实时访问(以便在API响应更改时立即通知程序)。 The API provided is non-realtime. 提供的API是非实时的。 What I want is something similar to Twitter's streaming API( https://dev.twitter.com/docs/streaming-api ). 我想要的是类似于Twitter的流API( https://dev.twitter.com/docs/streaming-api )。

I could send an API call every second but that would be too inefficient. 我可以每秒发送一次API调用,但是效率太低。 What would be better ways to do this? 有什么更好的方法可以做到这一点? I'll probably be doing this in Python or Node.js. 我可能会在Python或Node.js中进行此操作。

Since you're the client you have absolutely no way of knowing if the API response changes other than polling the API every few seconds. 因为您是客户端,所以除了每隔几秒钟轮询一次API之外,您完全无法知道API响应是否发生了变化。

reduce API calls by using the minimum time you're guaranteed to have no changes or the maximum time you can afford not knowing of changes. 通过使用可以保证没有更改的最短时间或可以承受的不知道更改的最长时间来减少API调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM