Chapter 5. Real-Time Connectivity

We can all agree that APIs are great. They open up silos to a wealth of data and functionality, but the vast majority of these Web APIs use the HTTP request-response model, requiring the client to make a request to a server and wait for a response in an interactive fashion. This is fine for the majority of our examples so far, such as sending a Tweet, adding a contact, etc. But what about when you actively want to retrieve updates about a particular resource, such as who’s talking about my company on Twitter today? You wouldn’t have someone sitting there issuing a request every 5 minutes would you? No, ideally you want to be notified in a real-time fashion when someone is talking about your company or when something happens to your account.

One traditional solution is polling, whereby a request with your particular search terms is scheduled to periodically call an API, process the response, and then repeat. This results, however, in developers calling these APIs over and over again to get updates, only to find out nothing has changed. This process constantly uses up resources and is not acceptable to either the API consumer or the API provider. If you’re just using Twitter to see what your friends are chatting about, then waiting 30 seconds to a minute to call the API and filter out the duplicate messages might be fine, but if you’re relying on these APIs for sales leads or financial data, then polling just won’t do. This is where “real-time” technologies ...

Get Getting Started with Mule Cloud Connect now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.