Coroutines

The coroutines extension package for Fuel.

Installation

You can download and install fuel-coroutines with Maven and Gradle. The coroutines package has the following dependencies:

  • KotlinX Coroutines: 1.1.1

Gradle

implementation 'com.github.kittinunf.fuel:fuel:<latest-version>'
implementation 'com.github.kittinunf.fuel:fuel-coroutines:<latest-version>'

Maven

<dependency>
    <groupId>com.github.kittinunf.fuel</groupId>
    <artifactId>fuel</artifactId>
    <version>[LATEST_VERSION]</version>
</dependency>

<dependency>
    <groupId>com.github.kittinunf.fuel</groupId>
    <artifactId>fuel-coroutines</artifactId>
    <version>[LATEST_VERSION]</version>
</dependency>

Usage

Coroutines module provides extension functions to wrap a response inside a coroutine and handle its result. The coroutines-based API provides equivalent methods to the standard API (e.g: responseString() in coroutines is awaitStringResponseResult()).

There are functions to handle Result object directly too.

It also provides useful methods to retrieve the ByteArray,String or Object directly. The difference with these implementations is that they throw exception instead of returning it wrapped a FuelError instance.

Handling objects other than String (awaitStringResponseResult()) or ByteArray (awaitByteArrayResponseResult()) can be done using awaitObject, awaitObjectResult or awaitObjectResponseResult.

Last updated

Was this helpful?