MoviebaseApp / tmdb-kotlin

🎬 Modern powerful TMDB API to fetch movies and TV shows for Kotlin Multiplatform.
https://www.moviebase.app
Apache License 2.0
205 stars 20 forks source link

Allow clients to customize HttpClient #27

Closed chrisbanes closed 1 year ago

chrisbanes commented 1 year ago

This PR adds a (HttpClientConfig<*>.() -> Unit) constructor parameter to Tmdb3 and Tmdb4, allowing clients to customize the Ktor client as they wish.

My primary use case is to enable persistent Http caching (https://ktor.io/docs/client-caching.html#persistent_cache), but there are lots of other use cases too.

ChrisKruegerDev commented 1 year ago

Nice, thanks! 👍

Started with PR #28 and some further parameters, it might be useful to structure the config. I thought something like this

        val tmdb = Tmdb3 {
            tmdbApiKey = "key"

            accountCredentials {
                // accessToken, refreshToken
            }

            httpClientConfig {
                install(HttpCache) {
                    // ...
                }
            }
        }
ChrisKruegerDev commented 1 year ago

If you want to add your custom OkHttp client, we add the field customHttpClient.