Coder Social home page Coder Social logo

alexxxdev / fuel-comfy Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 4.0 5.54 MB

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

License: Apache License 2.0

Kotlin 88.62% HTML 11.38%
kotlin kotlin-android kotlin-library fuel probe

fuel-comfy's Introduction

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

fuel-comfy's People

Contributors

alexxxdev avatar dependabot[bot] avatar fossabot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.