Skip to content

Instantly share code, notes, and snippets.

@Syex
Last active May 24, 2019 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Syex/3c9314afd90e8e5fd6b59ba19cdaca40 to your computer and use it in GitHub Desktop.
Save Syex/3c9314afd90e8e5fd6b59ba19cdaca40 to your computer and use it in GitHub Desktop.
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