Using jQuery AJAX with RxJS

One use case that is particularly compelling for RxJS is its integration with jQuery's AJAX library. Dealing with multiple callbacks in JavaScript can be a particularly daunting affair, especially because in JavaScript it is much harder to track down errors due to the dynamic nature of the language. Fortunately, using RxJS to make AJAX calls is quite straightforward. Let's look at the following example, a function to search through the Open Source projects hosted on GitHub:

var searchGitHub = function(term) {   var params = {     url: "http://github.com/api/v2/json/repos/search/" + encodeURI(term),     data: 'json'   };   return $.ajaxAsObservable(params)     .Select(function(x) { return x.data.repositories });

Get Programming Reactive Extensions and LINQ 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.