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.
All of the pre-requisites in the Getting Started guide apply as normal.
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.12.0'
}
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());
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());
});