Skip to content

Instantly share code, notes, and snippets.

@Syex

Syex/MoviesApi.kt

Last active May 24, 2019
Embed
What would you like to do?
private val client = HttpClient(clientEngine) {
install(JsonFeature) {
serializer = KotlinxSerializer()
}
}
suspend fun getPopularMovies(): PopularMoviesEntity {
val response = client.get<HttpResponse> {
url {
protocol = URLProtocol.HTTPS
host = "api.themoviedb.org/4"
encodedPath = "/discover/movie"
parameter("sort_by", "popularity.desc")
header("Authorization", "Bearer $yourApiKey")
}
}
val jsonBody = response.readText()
return Json.parse(PopularMoviesEntity.serializer(), jsonBody)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.