Creating a REST client API using Reactive Extensions (Rx)
Posted
by Jonas Follesø
on Stack Overflow
See other posts from Stack Overflow
or by Jonas Follesø
Published on 2010-05-14T10:09:54Z
Indexed on
2010/05/14
10:14 UTC
Read the original article
Hit count: 329
system.reactive
|.NET
I'm trying to get my head around the right use cases for Reactive Extensions (Rx). The examples that keeps coming up are UI events (drag and drop, drawing), and suggestions that Rx is suitable for asynchronous applications/operations such as web service calls.
I'm working on an application where I need to write a tiny client API for a REST service. I need to call four REST end-points, three to get some reference data (Airports, Airlines, and Statuses), and the fourth is the main service that will give you flight times for a given airport.
I have created classes exposing the three reference data services, and the methods look something like this:
public Observable<Airport> GetAirports()
public Observable<Airline> GetAirlines()
public Observable<Status> GetStatuses()
public Observable<Flights> GetFlights(string airport)
In my GetFlights method I want each Flight to hold a reference the Airport it's departing from, and the Airline operating the flight. To do that I need the data from GetAirports and GetAirlines to be available.
My initial thinking was something like this:
- Write a Rx Query that will Subscribe on the three reference services (Airports, Airlines and Statuses)
- Add results into a Dictionary (airline code and Airline object)
- When all three GetAirports, GetAirlines and GetStatuses are complete, then return the GetFlights IObservable.
Is this a reasonable scenario for Rx? I'm developing on the Windows Phone 7, so I'm not sure if there are major differences in the Rx implementations across the different platforms.
© Stack Overflow or respective owner