Skip to content

Latest commit

 

History

History
54 lines (43 loc) · 1.78 KB

README.md

File metadata and controls

54 lines (43 loc) · 1.78 KB

Rx Bindings

The Rx Bindings provide a facade to the Amplify library. Instead of using Amplify's native callback interface, you can interact with Amplify APIs by means of RxJava3 Observable, Single, and Completable.

For more information see the public documentation and this blog post.

Usage

Pre-requisites

All of the pre-requisites in the Getting Started guide apply as normal.

Gradle

To start using the Rx APIs, take an implementation dependency on this library. In your module's build.gradle:

dependencies {
    // Add this line.
    implementation 'com.amplifyframework:rxbindings:2.1.0'
}

Initialization

Initialize Amplify through the RxAmplify facade instead of through Amplify directly. The RxAmplify facade exposes the same functionalities as the core Amplify facade:

RxAmplify.addPlugin(new AWSAPIPlugin());
RxAmplify.configure(getApplicationContext());

Basic Example

This example will query a GraphQL API for models of type Person. If the query returns a successful response with data, each one will be printed out.

RxAmplify.API.query(Person.class)
    .map(response -> response.data())
    .flatMapObservable(results -> Observable.fromIterable(results))
    .subscribe(person -> {
        Log.i(TAG, "Found a person named " + person.getFirstName());
    });