The easiest HTTP networking library for Kotlin/Android

Last update: Jun 17, 2022

Fuel

jcenter mavenCentral Build Status Codecov

The easiest HTTP networking library for Kotlin/Android.

You are looking at the documentation for 2.x.y.. If you are looking for the documentation for 1.x.y, checkout the 1.16.0 README.md

Features

  • HTTP GET/POST/PUT/DELETE/HEAD/PATCH requests in a fluent style interface
  • Asynchronous and blocking requests
  • Download as a file
  • Upload files, Blobs, DataParts as multipart/form-data
  • Cancel asynchronous request
  • Debug logging / convert to cUrl call
  • Deserialization into POJO / POKO
  • Requests as coroutines
  • API Routing

Installation

We offer maven and jitpack installations. Maven via bintray only has stable releases but jitpack can be used to build any branch, commit and version.

Maven

You can download and install Fuel with Maven and Gradle. The core package has the following dependencies:

  //core
  implementation 'com.github.kittinunf.fuel:fuel:<latest-version>'
  
  //packages
  implementation 'com.github.kittinunf.fuel:<package>:<latest-version>'

Make sure to include jcenter() or mavenCentral() in your repositories

repositories {
  jcenter() //or mavenCentral()
}

Each of the extensions / integrations has to be installed separately.

Package Description
fuel Core package
fuel-android Android: Automatically invoke handler on Main Thread when using Android Module
fuel-coroutines KotlinX: Execution with coroutines
fuel-forge Deserialization: Forge
fuel-gson (De)serialization: Gson
fuel-jackson Deserialization: Jackson
fuel-json Deserialization: Json
fuel-kotlinx-serialization (De)serialization: KotlinX Serialization
fuel-livedata Android Architectures: Responses as LiveData
fuel-moshi Deserialization: Moshi
fuel-reactor Reactive Programming: Responses as Mono (Project Reactor 3.x)
fuel-rxjava Reactive Programming: Responses as Single (RxJava 2.x)
fuel-stetho Utility: Debug utility for Android on Chrome Developer Tools, Stetho

Jitpack

If you want a SNAPSHOT distribution, you can use Jitpack

repositories {
  maven(url = "https://www.jitpack.io") {
    name = "jitpack"
  }
}

dependencies {
  //core
  implementation(group = "com.github.kittinunf.fuel", name = "fuel", version = "-SNAPSHOT")
  
  //packages
  // replace <package> with the package name e.g. fuel-coroutines
  implementation(group = "com.github.kittinunf.fuel", name = "<package>", version = "-SNAPSHOT")
}

or

dependencies {
  //core and/or packages
  // replace <package> with the package name e.g. fuel-coroutines
  listof("fuel", "<package>").forEach {
    implementation(group = "com.github.kittinunf.fuel", name = it, version = "-SNAPSHOT")
  }
}

Configuration

  • group is made up of com.github as well as username and project name

  • name is the subproject, this may be any of the packages listed in the installation instructions eg. fuel, fuel-coroutines, fuel-kotlinx-serialization, etc

  • version can be the latest master-SMAPSHOT or -SNAPSHOT which always points at the HEAD or any other branch, tag or commit hash, e.g. as listed on jitpack.io.

We recommend not using SNAPSHOT builds, but a specific commit in a specific branch (like a commit on master), because your build will then be stable.

Build time-out

Have patience when updating the version of fuel or building for the first time as jitpack will build it, and this may cause the request to jitpack to time out. Wait a few minutes and try again (or check the status on jitpack).

NOTE: do not forget to add the kotlinx repository when using coroutines or serialization

Forks

Jitpack.io also allows to build from fuel forks. If a fork's username is $yourname,

  • adjust group to com.github.$yourName.fuel
  • and look for version on https://jitpack.io/#$yourName/Fuel

Quick start

Fuel requests can be made on the Fuel namespace object, any FuelManager or using one of the String extension methods. If you specify a callback the call is async, if you don't it's blocking.

Async Usage Example

import com.github.kittinunf.fuel.httpGet
import com.github.kittinunf.result.Result;

fun main(args: Array<String>) {

    val httpAsync = "https://httpbin.org/get"
        .httpGet()
        .responseString { request, response, result ->
            when (result) {
                is Result.Failure -> {
                    val ex = result.getException()
                    println(ex)
                }
                is Result.Success -> {
                    val data = result.get()
                    println(data)
                }
            }
        }

    httpAsync.join()
}

Blocking Usage Example

import com.github.kittinunf.fuel.httpGet
import com.github.kittinunf.result.Result;

fun main(args: Array<String>) {

    val (request, response, result) = "https://httpbin.org/get"
        .httpGet()
        .responseString()

    when (result) {
        is Result.Failure -> {
            val ex = result.getException()
            println(ex)
        }
        is Result.Success -> {
            val data = result.get()
            println(data)
        }
    }

}

// You can also use Fuel.get("https://httpbin.org/get").responseString { ... }
// You can also use FuelManager.instance.get("...").responseString { ... }

Fuel and the extension methods use the FuelManager.instance under the hood. You can use this FuelManager to change the default behaviour of all requests:

FuelManager.instance.basePath = "https://httpbin.org"

"/get"
  .httpGet()
  .responseString { request, response, result -> /*...*/ }
// This is a GET request to "https://httpbin.org/get"

Detailed usage

Check each of the packages documentations or the Wiki for more features, usages and examples. Are you looking for basic usage on how to set headers, authentication, request bodies and more? fuel: Basic usage is all you need.

Basic functionality

Responses

(De)serialization

Utility

Other libraries

If you like Fuel, you might also like other libraries of mine;

  • Result - The modelling for success/failure of operations in Kotlin
  • Fuse - A simple generic LRU memory/disk cache for Android written in Kotlin
  • Forge - Functional style JSON parsing written in Kotlin
  • ReactiveAndroid - Reactive events and properties with RxJava for Android SDK

Credits

Fuel is brought to you by contributors.

Licenses

Fuel is released under the MIT license.

GitHub

https://github.com/kittinunf/Fuel
Comments
  • 1. Add suspending implenetation client

    Description

    In this pr I am hoping to create a suspending implementation of the httpClient so that, should a user so wish they could avoid using threads.

    Huge thank you/love/creative respect/kudos must go to both @iNoles, @lucasvalenteds and @SleeplessByte who all helped me get this running at points I was completely stuck

    Fixes #431

    Check all that apply

    • [x] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • [ ] Refactoring (change which changes the current internal or external interface)
    • [x] This change requires a documentation update

    How Has This Been Tested?

    This pr changes the implementation but the test remain the same as the object was not change the behaviour

    Checklist:

    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [ ] I have made corresponding changes to the documentation, if necessary
    • [x] My changes generate no new compiler warnings
    • [ ] I have added tests that prove my fix is effective or that my feature works
    • [x] New and existing unit tests pass locally with my changes
    Reviewed by markGilchrist at 2018-09-21 12:58
  • 2. Some Async Coroutine Functions

    Thank you for submitting your Pull Request. Please make sure you have familiarised yourself with the Contributing Guidelines before continuing.

    Description

    I added async block for some functions and left blocking one alone. I was a bit curious why somebody else didn't added this one.

    Fixes #429

    Type of change

    Check all that apply

    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • [ ] Refactoring (change which changes the current internal or external interface)
    • [ ] This change requires a documentation update

    How Has This Been Tested?

    In case you did not include tests describe why you and how you have verified the changes, with instructions so we can reproduce. If you have added comprehensive tests for your changes, you may ommit this section.

    Checklist:

    • [x] I have performed a self-review of my own code
    • [ ] I have commented my code, particularly in hard-to-understand areas
    • [ ] I have made corresponding changes to the documentation, if necessary
    • [x] My changes generate no new compiler warnings
    • [x] I have added tests that prove my fix is effective or that my feature works
    • [x] New and existing unit tests pass locally with my changes
    Reviewed by iNoles at 2018-09-14 01:50
  • 3. Out of memory when downloading file.

    When i download a big file I am getting an out of memory error in Android. If the file is small there is no problem.

    Maybe it can be related to this.

    Out of memory error or this Out of memory error 2

    Reviewed by Yayo-Arellano at 2016-08-12 08:55
  • 4. [fuel-jackson] Add Request.body(any: Any) extension method

    I'd like to be able to make requests like this:

     val (request, response, result) = Fuel.post(url)
                .body(MyCustomRequestBodyObject(...)) // here
                .responseObject<MyCustomResponseBodyObject>()
    

    Currently I have an extension method in my project which allows this:

    fun Request.body(any: Any) = body(mapper...)
    

    Would be nice if this was a part of the fuel-jackson module.

    Reviewed by david-wg2 at 2019-07-17 14:35
  • 5. Add HTTP status code 303 as valid redirect

    Currently Fuel handles HTTP Status Code 303 as an error. It should be handled as a redirect though: https://en.wikipedia.org/wiki/HTTP_303 https://httpstatuses.com/303

    Reviewed by ParkerK at 2017-08-06 19:37
  • 6. [Release] New Version 1.16.0

    Description

    This PR aims to release Fuel new version 1.16.0. This will target Kotlin 1.3 with new coroutine.

    Type of change

    Check all that apply

    • [x] Release new version

    How Has This Been Tested?

    Checklist:

    • [x] I have performed a self-review of my own code
    Reviewed by kittinunf at 2018-10-15 04:07
  • 7. #246, #168: Add Kotlin Coroutines support

    This pull requests adds some suspend functions to the Request class. They were added in a new module called fuel-coroutines and are intended to allows the developers to avoid callbacks while using asynchronous calls.

    Reviewed by lucasvalenteds at 2018-02-23 04:59
  • 8. :sparkles: [core] PATCH without http-method-override header

    Description

    This PR allows PATCH requests to be made without a http-method-override header

    Type of change

    Check all that apply

    • [ ] Bug fix (a non-breaking change which fixes an issue)
    • [x] New feature (a non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • [ ] Refactoring (a change which changes the current internal or external interface)
    • [ ] This change requires a documentation update

    How Has This Been Tested?

    In case you did not include tests describe why you and how you have verified the changes, with instructions so we can reproduce. If you have added comprehensive tests for your changes, you may omit this section.

    I have not created tests to verify that this PR is working, however I have modified the sample android app and I can confirm that a patch request is working with httpbin.org. If a test case is required then I'm willing to add one (might need some help with this)

    Checklist:

    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [ ] I have made corresponding changes to the documentation, if necessary
    • [ ] My changes generate no new compiler warnings
    • [ ] I have added tests that prove my fix is effective or that my feature works
    • [ ] New and existing unit tests pass locally with my changes
    • [ ] Inspect the bytecode viewer, including reasoning why
    Reviewed by bb441db at 2018-12-12 18:14
  • 9. Add reviewdog to bark at our violations

    Description

    This PR adds review dog to travis CI. It is a continuation over #476. So, it can report our violations at the line they occurs.

    Type of change

    Check all that apply

    • [x] Linter support

    How Has This Been Tested?

    In case you did not include tests describe why you and how you have verified the changes, with instructions so we can reproduce. If you have added comprehensive tests for your changes, you may omit this section.

    Checklist:

    • [x] I have performed a self-review of my own code
    • [ ] I have commented my code, particularly in hard-to-understand areas
    • [ ] I have made corresponding changes to the documentation, if necessary
    • [ ] My changes generate no new compiler warnings
    • [ ] I have added tests that prove my fix is effective or that my feature works
    • [ ] New and existing unit tests pass locally with my changes
    • [ ] Inspect the bytecode viewer, including reasoning why
    Reviewed by kittinunf at 2018-10-21 05:09
  • 10. Migrate Gradle scripts to Kotlin DSL

    This pull requests rewrites all Gradle build files from Groovy DSL to Kotlin DSL.

    The motivation to change them is to reduce duplication and maintenance effort by declaring versions in a single file and defining common logic in one place, which make them reusable. Better syntax highlight and autocomplete is expected too.

    At the moment, all tests are passing and Android Studio doesn't have any warnings.

    Improvements to make

    • Logic to build Android-based modules are not as reusable as JVM-based modules
    • Make sure publish plugin is working as expected. At the moment Gradle is loggin the warning below.
      Publication release not found in project :fuel-android.
      Publication release not found in project :fuel-livedata
      
    • Gradle found different versions of kotlin-stdlib, but tests are passing. The command below may help to identify them.
      ./gradlew dependencyInsight --configure compile --dependency kotlin-stdlib
      

    I'd love hear some feedback from you about using Kotlin instead of Groovy and also suggestions to improve the build scripts!

    Reviewed by lucasvalenteds at 2018-09-06 13:20
  • 11. Cannot access request header fields after connection is set

    Attempting to execute:

    "http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en".httpGet().response { request, response, result -> 
         println(request)
         println(response)
    }
    

    produces:

    java.lang.IllegalStateException: Cannot access request header fields after connection is set
         at com.github.kittinunf.fuel.toolbox.HttpClient.executeRequest(HttpClient.kt:69)
         at com.github.kittinunf.fuel.core.requests.TaskRequest.call(TaskRequest.kt:16)
         at com.github.kittinunf.fuel.core.requests.AsyncTaskRequest.call(AsyncTaskRequest.kt:13)
         at com.github.kittinunf.fuel.core.requests.AsyncTaskRequest.call(AsyncTaskRequest.kt:6)
         at java.util.concurrent.FutureTask.run(FutureTask.java:237)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
         at com.github.kittinunf.fuel.core.FuelManager$executor$2$1$1.run(FuelManager.kt:49)
         at java.lang.Thread.run(Thread.java:761)
    

    Using the cUrlLoggingRequestInterceptor I got the following curl that when executed on a terminal it works:

    curl -i -H "Accept-Encoding:compress;q=0.5, gzip;q=1.0" "http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en"

    Reviewed by mradzinski at 2017-08-26 09:37
  • 12. Does this library support Datadog integration?

    Feature Request

    Description

    I would like to integrate this library with Datadog and I cant find a way to do that

    Proposed Solution

    Add some config option to do the integration

    Alternatives I've considered

    I am using a custom Rest client that integrates with DD but it has some problems.

    Reviewed by Matias-Barrios at 2022-04-13 14:37
  • 13. httpGet does not render parameters correctly

    Bug Report

    Description

    Looking at the docs at https://github.com/kittinunf/fuel/blob/master/fuel/README.md:

    Fuel.get("https://httpbin.org/get", listOf("foo" to "foo", "bar" to "bar"))
        .url
    // https://httpbin.org/get?foo=foo&bar=bar
    

    However as far as I can see on Fuel of version 2.3.1, the parameters are dropped and the result is:

    https://httpbin.org/get
    

    Development Machine

    • OS: Mac
    • Fuel version: 2.3.1
    • Kotlin version: 1.6.10
    • JDK 17
    Reviewed by knyttl at 2022-03-03 15:15
  • 14. Allow to properly PATCH methods with JDK11+

    Feature Request

    This is a followup issue for https://github.com/kittinunf/Fuel/issues/274

    Description

    Currently PATCH methods are silently transformed to POST methods.

    However, in java 11+ (https://stackoverflow.com/a/64048579/922584) you can use the HttpRequest class to do what you want:

    val request = HttpRequest.newBuilder()
                   .uri(URI.create(uri))
                   .method("PATCH", HttpRequest.BodyPublishers.ofString(message))
                   .build()
    

    Proposed Solution

    It would be great if it was possible to leverage possibilities of JDK11+ and do correct PATCH requests as some services ignore the x-http-method-override header

    Reviewed by knyttl at 2022-01-28 09:38
  • 15. How to test or mock responseObject()

    Hi,

    I have been struggling to figure out how to properly test code that uses fuel. I have reviewed previous issues and people suggest things like:

    val someJson = "{\"key\":\"value\"}"
    manager.client = mockk<Client>()
    every { manager.client.executeRequest(any()).statusCode } returns 200
    every { manager.client.executeRequest(any()).data } returns someJson.toByteArray()
    

    This works ok when using responseString(), however when using responseObject(), I get errors like:

    Response(child of #2#3), [Failure: no answer found for: Response(child of #2#3).getBody$fuel()
    	com.github.kittinunf.fuel.core.FuelError$Companion.wrap(FuelError.kt:86)
    	com.github.kittinunf.fuel.core.DeserializableKt.response(Deserializable.kt:178)
    

    I have not been able to figure out how to successfully mock getBody or a Response and get it to work. I enjoy using this library but figuring out the testing path has been an obstacle. Do you have any suggestions?

    Thanks

    Reviewed by matteosimone at 2022-01-13 17:09
  • 16. Add support for IDNA 2008 (RFC 5891) when encoding URL (#819)

    Description

    Convert URL host to A-Label before making a request. IDNA object is provided by ICU4j dependency for JVM but on Android it is included in android.icu.text.IDNA so you may want to handle it differently for Android which I did not do.

    Fixes #819

    Type of change

    • [x] Bug fix (a non-breaking change which fixes an issue)
    • [ ] New feature (a non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
    • [ ] Refactoring (a change which changes the current internal or external interface)
    • [ ] This change requires a documentation update

    Checklist:

    • [x] I have performed a self-review of my own code
    • [ ] I have commented my code, particularly in hard-to-understand areas
    • [ ] I have made corresponding changes to the documentation, if necessary
    • [ ] My changes generate no new compiler warnings
    • [x] I have added tests that prove my fix is effective or that my feature works
    • [x] New and existing unit tests pass locally with my changes
    • [ ] Inspect the bytecode viewer, including reasoning why
    Reviewed by j-bernard at 2021-11-29 17:12
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀
🚀 A Complete Fast Android Networking Library that also supports HTTP/2 🚀

Fast Android Networking Library About Fast Android Networking Library Fast Android Networking Library is a powerful library for doing any type of netw

Jun 21, 2022
Volley is an HTTP library that makes networking for Android apps easier and, most importantly, faster.

Volley Volley is an HTTP library that makes networking for Android apps easier and, most importantly, faster. For more information about Volley and ho

Jun 24, 2022
LiteHttp is a simple, intelligent and flexible HTTP framework for Android. With LiteHttp you can make HTTP request with only one line of code! It could convert a java model to the parameter and rander the response JSON as a java model intelligently.

Android network framework: LiteHttp Tags : litehttp2.x-tutorials Website : http://litesuits.com QQgroup : 42960650 , 47357508 Android网络通信为啥子选 lite-htt

Apr 15, 2022
Kotlin-echo-client - Echo client using Kotlin with Ktor networking library
Kotlin-echo-client - Echo client using Kotlin with Ktor networking library

Overview This repository contains an echo server implemented with Kotlin and kto

Jan 5, 2022
:satellite: [Android Library] Simplified async networking in android
:satellite: [Android Library] Simplified async networking in android

Android library that simplifies networking in android via an async http client. Also featured in [Awesome Android Newsletter #Issue 15 ] Built with ❤︎

May 14, 2022
Flower - Super cool Android library to manage networking and database caching with ease

Flower Super cool Android library to manage networking and database caching with ease. It allows developers to use remote resources on-the-fly OR Comb

Jun 19, 2022
Android Asynchronous Networking and Image Loading
Android Asynchronous Networking and Image Loading

Android Asynchronous Networking and Image Loading Download Maven Git Features Kotlin coroutine/suspend support Asynchronously download: Images into Im

Jun 20, 2022
IceNet - Fast, Simple and Easy Networking for Android

IceNet FAST, SIMPLE, EASY This library is an Android networking wrapper consisting of a combination of Volley, OkHttp and Gson. For more information s

Jun 12, 2021
Latihan Networking dengan Retrofit
Latihan Networking dengan Retrofit

Latihan-Background-Process-dan-Networking-9 Latihan Networking dengan Retrofit Pada materi kali ini Anda akan belajar menggunakan Retrofit untuk menam

Nov 25, 2021
HttpMocker is a simple HTTP mocking library written in Kotlin to quickly and easily handle offline modes in your apps

HttpMocker HttpMocker is a very lightweight Kotlin library that allows to mock HTTP calls relying on either OkHttp or the Ktor client libraries. It ca

Apr 26, 2022
Kotlin HTTP requests library. Similar to Python requests.

khttp khttp is a simple library for HTTP requests in Kotlin. It functions similarly to Python's requests module. import khttp.get fun main(args: Arra

Jun 12, 2022
Ktorfit - a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit
Ktorfit - a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit

Ktorfit is a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit

Jun 16, 2022
Asynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads.

AndroidAsync AndroidAsync is a low level network protocol library. If you are looking for an easy to use, higher level, Android aware, http request li

Jun 17, 2022
Asynchronous Http and WebSocket Client library for Java

Async Http Client Follow @AsyncHttpClient on Twitter. The AsyncHttpClient (AHC) library allows Java applications to easily execute HTTP requests and a

Jun 15, 2022
Java HTTP Request Library

Http Request A simple convenience library for using a HttpURLConnection to make requests and access the response. This library is available under the

Jun 15, 2022
Unirest in Java: Simplified, lightweight HTTP client library.

Unirest for Java Install With Maven: <!-- Pull in as a traditional dependency --> <dependency> <groupId>com.konghq</groupId> <artifactId>unire

Jun 23, 2022
super simple library to manage http requests.

HttpAgent super simple library to manage http requests. Gradle dependencies { implementation 'com.studioidan.httpagent:httpagent:[email protected]' } No

Oct 24, 2021
Unirest in Java: Simplified, lightweight HTTP client library.

Unirest for Java Install With Maven: <!-- Pull in as a traditional dependency --> <dependency> <groupId>com.konghq</groupId> <artifactId>unire

Jun 17, 2022
Multiplatform coroutine-based HTTP client wrapper for Kotlin

networkinkt This is a lightweight HTTP client for Kotlin. It relies on coroutines on both JS & JVM platforms. Here is a simple GET request: val text =

Jun 24, 2020