Slide 33
Slide 33 text
okhttp
class UserApiClient @Inject constructor(val mapper: ObjectMapper, val client: OkHttpClient,
@Named("apiDomain") val apiDomain: String
) {
fun getUser(ids: List): List {
val urlBuilder = HttpUrl.Builder().scheme(“https").host(apiDomain)
.addPathSegment("users").addPathSegment(ids.joinToString(","))
val request = Request.Builder().url(urlBuilder.build()).build()
val response = client.newCall(request).execute()
if (response.code() != 200) {
throw RuntimeException("api error")
}
val raw = response.body().string()
val tr = object : TypeReference>() {}
return mapper.readValue>(raw, tr)
}
}
‣ Microservices間の通信
‣ data classにdeserialize