Wrapping a Legacy Library in Rx

image from Unsplash.com by Ludde Lorentz, pictures a downward view of a winding staircase

Using an AWS S3 Upload as an Example

The Rx Universe is vast and by me largely unexplored, so there is an opportunity to learn something new every day.

The AWS S3 Android SDK does not support Rx so I decided to Rx-ify it. In this example we will add a call uploading a file directly to AWS and then will post the results to a previously implemented API.

I will not go into details on how to implement Amazon’s S3 File Transfer Utility, you can find it here.

Making REST call to an endpoint is easy, if you use Retrofit2, and I suggest you do! But it gets a little more complicated if you have to deal with a 3rd party SDK that does not return an Observable.

Here’s how I wrapped it:

In this case I am using an intermediate model to pass the results of the file transfer to downstream receivers.

If your existing API call implementation looked something like this before:

Now it turns into a slightly more complex, but still very readable construct:

Enjoy and happy coding!


Do you have a project in mind? We’d love to work with you. If you’d like an opportunity to work on projects with us, check out our Careers page. We’re hiring!

Leave a Comment