Skip to content

alexxxdev/fuel-comfy

Repository files navigation

fuel-comfy

Android Arsenal FOSSA Status License
Build Status Build Status Hits-of-Code
codecov Codacy Badge codebeat badge
CodeFactor BCH compliance
Quality Gate Status Coverage
Kotlin Fuel

More comfortable use of Fuel as in Retrofit or Feign for Kotlin/Android

Basics

Usage typically looks like this

@FuelInterface
interface GitHubService {

    @Get("repos/{owner}/{repo}/contributors")
    fun contributors(@Param("owner") owner: String, @Param("repo") repo: String): Result<Contributor, Exception>
}

FuelManager.instance.basePath = "https://api.github.com/"

val service = FuelManager.instance.setInterface(GitHubService::class)
val contributors = service.contributors("alexxxdev", "fuel-comfy")
contributors.fold({ list ->
            // TODO
        }, { exception ->
            // TODO
        })

Features

  • HTTP GET/POST/PUT/DELETE/HEAD/PATCH requests
  • Serialization/Deserialization using fuel-kotlinx-serialization
  • Support suspend function
  • Serialization/Deserialization using Gson
  • Maybe something else ...

Interface Annotations

@FuelInterface

Defines the interface for fuel-comfy

@Get / @Post / @Put / @Delete / @Head / @Patch

Defines the GET/POST/PUT/DELETE/HEAD/PATCH HttpMethod and UriTemplate for request. Expressions, values wrapped in curly-braces {expression} are resolved using their corresponding @Param annotated parameters.

@Param

Defines a template variable, whose value will be used to resolve the corresponding template Expression, by name.

@Header

When used on a Interface, will be applied to every request. When used on a Method, will apply only to the annotated method.

@FuelInterface
@Headers("Accept: application/json")
interface GitHubService {

  @Headers("Content-Type: application/json")
  @POST("...")
  fun post()
}

@QueryMap

Defines a Map of name-value pairs, to expand into a query string.

@FuelInterface
interface GitHubService {

  @GET("...")
  fun get(@QueryMap params: Map<String, Any>)
}

@Query

Defines name-value pair, to expand into a query string.

@FuelInterface
interface GitHubService {

  @GET("...")
  fun get(@Query("id") id: Int)
}

@Body

Defines a request body

@FuelInterface
interface GitHubService {

  @GET("...")
  fun get(@Body contributor: Contributor)
}




Installation

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Add the dependency

dependencies {
    implementation 'com.github.alexxxdev.fuel-comfy:api:<version>'    
    kapt 'com.github.alexxxdev.fuel-comfy:processor:<version>'
    
    //optional
    kapt 'com.github.alexxxdev.fuel-comfy:processor-coroutines:<version>'
    kapt 'com.github.alexxxdev.fuel-comfy:processor-gson:<version>'
}

License

FOSSA Status