title: Web API Rx Implementation
body: <p>I am currently trying to work through an example of building a Functional Reactive API similar to Netflix as partially defined by Ben Christensen <a href="http://techblog.netflix.com/2013/02/rxjava-netflix-api.html" rel="nofollow">here</a>.</p>
  
  <p>I setup a default ASP.NET Web API project and added a controller for retrieving a user like so:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class UserController : ApiController
  {
      // GET api/user
      public IObservable&lt;User&gt; Get()
      {
          var temp = new User { FirstName = "Keith", LastName = "LaForce" };
          return Observable.Create&lt;User&gt;(
  
              (IObserver&lt;User&gt; observer) =&gt;
              {
                  observer.OnNext(temp);
                  observer.OnCompleted();
                  //Thread.Sleep(1000);
                  return Disposable.Create(() =&gt; Console.WriteLine("Observer has unsubscribed"));
                  //or can return an Action like 
                  //return () =&gt; Console.WriteLine("Observer has unsubscribed"); 
              });
      }
  }
  </code></pre>
  
  <p>I am then trying to make a call utilizing RxJS to process this Observable API method with the following code:</p>
  
  <pre class="lang-js prettyprint-override"><code>function getValues() {
      var promise = $.ajax({
          url: 'http://url-where-api-lives/api/user'
      }).promise();
      return Rx.Observable.fromPromise(promise);
  };
  
  var suggestions = getValues();
  
  suggestions.subscribe(function (data) {
      console.log(data);
  }, function (e) {
     console.log(e);
  });
  </code></pre>
  
  <p>My console.log in the JS only ever prints out an empty Object {}.  My question is, how do you properly return an Rx Observable from an WebAPI controller and how do you process the results from the client?  Are you not able to do this, but rather the WebAPI should return an Enumerable and the Service Layer should be in charge of asynchronous work and return an Observable?</p>