Retrofit Flow Call Adapter Factory For Android

Overview

Summary

Android Retrofit FlowCallAdapterFactory

Retrofit 2 CallAdapter.Factory for kotlin coroutine's Flow<T>

Usage

Add FlowCallAdapterFactory as Call adapter when building your Retrofit instance:

val retrofit = Retrofit.Builder()
    .baseUrl("https://thdev.tech/")
    .addConverterFactory(StringConverterFactory())
    .addCallAdapterFactory(FlowCallAdapterFactory())
    .build()

Your service methods can now use Flow<T> as their return type.

interface Service {
    @GET("/example")
    fun getExample(): Flow<Example>

    @GET("/example")
    fun getExample(): Flow<Response<Example>>
}

License

Copyright 2021 TaeHwan-dev

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
: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 ❤︎

Android network client based on Cronet. This library let you easily use QUIC protocol in your Android projects

Android network client based on Cronet. This library let you easily use QUIC protocol in your Android projects

Android Easy Http - Simplest android http request library.
Android Easy Http - Simplest android http request library.

Android Easy Http Library 繁體中文文檔 About Android Easy Http Library Made on OkHttp. Easy to do http request, just make request and listen for the respons

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

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.

OkHttp See the project website for documentation and APIs. HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP

A type-safe HTTP client for Android and the JVM

Retrofit A type-safe HTTP client for Android and Java. For more information please see the website. Download Download the latest JAR or grab from Mave

Android client for ProjectRTC - a WebRTC demo

AndroidRTC WebRTC Live Streaming An Android client for ProjectRTC. It is designed to demonstrate WebRTC video calls between androids and/or desktop br

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

Easy, asynchronous, annotation-based SOAP for Android

IceSoap IceSoap provides quick, easy, asynchronous access to SOAP web services from Android devices. It allows for SOAP responses to be bound to Java

Comments
  • Interceptor에서 크래시 발생

    Interceptor에서 크래시 발생

    class LogInterceptor : Interceptor, KoinComponent {
        override fun intercept(chain: Interceptor.Chain): Response {
            val request = chain.request()
            val response = chain.proceed(request)
            val bodyString = response.body()!!.string()
            val body = ResponseBody.create(response.body()!!.contentType(), bodyString)
    
            return response.newBuilder().body(body).build()
        }
    }
    

    위 코드와 같이 Interceptor를 적용된 프로젝트에서, API 호출도중(로딩상태) 네트워크가 끊긴 상태가 되었을때 Interceptor에서 크래시가 발생합니다.

    java.net.UnknownHostException: Unable to resolve host "api.test.com": No address associated with hostname
        at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:156)
        at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
        at java.net.InetAddress.getAllByName(InetAddress.java:1152)
        at okhttp3.Dns.lambda$static$0(Dns.java:39)
        at okhttp3.-$$Lambda$Dns$9evC3uO-H_z08sS9O-4-hLhZ8es.lookup(Unknown Source:0)
        at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:171)
        at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.java:135)
        at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:84)
        at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.java:187)
        at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.java:108)
        at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.java:88)
        at okhttp3.internal.connection.Transmitter.newExchange(Transmitter.java:169)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
        at kr.co.inforexseoul.radioproject.util.interceptor.LogInterceptor.intercept(LogInterceptor.kt:18)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
        at kr.co.inforexseoul.radioproject.util.interceptor.HeaderInterceptor.intercept(HeaderInterceptor.kt:22)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229)
        at okhttp3.RealCall$AsyncCall.execute(RealCall.java:172)
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:920)
    Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
        at libcore.io.Linux.android_getaddrinfo(Native Method)
        at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:136)
        at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:221)
        at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:136)
        at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
    	... 34 more
    
    opened by sun5066 2
Releases(1.0.0)
Owner
TaeHwan
Android Developer
TaeHwan
Kotlin-REST-Retrofit - Simple client to consume a REST API with Retrofit using Kotlin

Kotlin REST Retrofit Sencillo cliente para consumir una API REST con Retrofit us

José Luis González Sánchez 5 Nov 4, 2022
Write your asynchronous Network / IO call painlessly in Kotlin !!

Asynkio : Write asynced IO/ Network calls painlessly on android | | | Documentation Write your network requests, IO calls in android with Kotlin seaml

Nikhil Chaudhari 82 Jan 26, 2022
Handle various HTTP status code by safe api call with Result sealed class

retrofit2-safe-api-call Handle various HTTP status code by safe api call with Result sealed class Library Retrofit2 OkHttp3 Gson Coroutine DI : Koin V

Jaesung Lee 2 May 16, 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 is a HTTP client/Kotlin Symbol Processor for Kotlin Multiplatform (Js, Jvm, Android, iOS, Linux) using KSP and Ktor clients inspired by Retrofit

Jens Klingenberg 637 Dec 25, 2022
Mock your datas for Okhttp and Retrofit in json format in just a few moves

okhttp-json-mock This simple library helps you mock your data for using with okhttp+retrofit in json format in just a few moves. it forwards the reque

Mad Mirrajabi 240 Nov 25, 2022
Retrofit + OkHttp3 + coroutines + LiveData打造一款网络请求框架

Network-Demo Retrofit + OkHttp3 + coroutines + LiveData打造一款网络请求框架 一个好的网络框架需要有那些特点呢? 请求 当然这个请求不单单是发送请求这么简单,它包括请求相关的一系列配置是否简易、发送模式是否灵活切换、请求头信息是否易处理、请求参数

图你怀中安稳 77 Nov 14, 2022
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

Ubean 0 Nov 25, 2021
Exercicio praticando Retrofit

MarsPhotos - Starter Code Starter code for Android Basics in Kotlin. Introduction Using this stater code you will create MarsPhotos is a demo app that

Lucas Caetano 1 Nov 26, 2021
A basic list application designed using MVVM pattern with Retrofit, OkHttp, and Hilt for dependency injection

FRExercise A basic list application designed using MVVM pattern with Retrofit, O

null 0 Dec 22, 2021