<commit_before>RxSSE
=====

[Server-Sent Events][sse] client for Android and Java applications.

Built with [Kotlin][kotlin], [RxJava][rxjava] and [OkHttp][okhttp].


License<commit_msg>Update README with usage examples<commit_after>RxSSE
=====

[Server-Sent Events][sse] client for Android and Java applications.

Built with [Kotlin][kotlin], [RxJava][rxjava] and [OkHttp][okhttp].


Usage
-----

Create an `RxSSE` instance with a default client:

```kotlin
val rxsse = RxSSE()
```

Or with a pre-configured client:

```kotlin
val client = OkHttpClient.Builder().build()
val rxsse = RxSSE(client)
```

Then use it to connect to URLs:

```kotlin
rxsse
    .connectTo("https://localhost/events")
    .onBackpressureLatest()
    .subscribeOn(Schedulers.io(), false)
    .subscribe { Log.i(TAG, "Received: $it") }
```

Notice that the returned `Flowable` does not define a backpressure strategy.
You should define a strategy in order to prevent `MissingBackpressure` errors.
In this case `onBackpressureLatest()` is used, but there are others.

You can also use it with customized requests:

```kotlin
val request = Request.Builder().url(myUrl).build()
rxsse
    .connectTo(request)
    .onBackpressureLatest()
    .subscribeOn(Schedulers.io(), false)
    .subscribe { Log.i(TAG, "Received: $it") }
```

You can use RxJava's `retry` operators to reconnect if the connection
is lost or there is an error.

Attempt to reconnect with a fixed timeout:

```kotlin
rxsse
    .connectTo("https://localhost/events")
    .onBackpressureLatest()
    .retryWhen { it.flatMap { Flowable.timer(5, TimeUnit.SECONDS) } }
    .subscribeOn(Schedulers.io(), false)
    .subscribe { Log.i(TAG, "Received: $it") }
```

Finally, don't forget to unsubscribe when you are done to close the connection:

```kotlin
val disposable = rxsse
    .connectTo("https://localhost/events")
    .onBackpressureLatest()
    .subscribeOn(Schedulers.io(), false)
    .subscribe { Log.i(TAG, "Received: $it") }

// Close the connection
disposable.dispose()
```


Download
--------

Available soon.


TODO
----

 * Add tests.

 * Implement automatic retries.

 * Automatically send `Last-Event-ID` header on retries.


Contributing
------------

Contributions and feedback are welcome!

Please create an issue to discuss it first :)


License
{'fraction_non_alphanumeric': 0.13745106568073076, 'fraction_numerical': 0.00043497172683775554, 'mean_word_length': 4.0, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1706466', 'n_tokens_mistral': 773, 'n_tokens_neox': 723, 'n_words': 227}