More comfortable use of Fuel as in Retrofit or Feign for Kotlin/Android
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
})
- HTTP GET/POST/PUT/DELETE/HEAD/PATCH requests
- Serialization/Deserialization using fuel-kotlinx-serialization
- Support
suspend
function - Serialization/Deserialization using Gson
- Maybe something else ...
Defines the interface for fuel-comfy
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.
Defines a template variable, whose value will be used to resolve the corresponding template Expression, by name.
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()
}
Defines a Map of name-value pairs, to expand into a query string.
@FuelInterface
interface GitHubService {
@GET("...")
fun get(@QueryMap params: Map<String, Any>)
}
Defines name-value pair, to expand into a query string.
@FuelInterface
interface GitHubService {
@GET("...")
fun get(@Query("id") id: Int)
}
Defines a request body
@FuelInterface
interface GitHubService {
@GET("...")
fun get(@Body contributor: Contributor)
}
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>'
}