728x90

KTOR 3

[Ktor] 3. Response

Ktor Client ๊ฐ€์ด๋“œ ์š”์•ฝ ์ •๋ฆฌ Ktor Documents ๊ธฐ์ค€ ๋ฒ„์ „: 1.6.2 ์‹œ๋ฆฌ์ฆˆ 1. ํด๋ผ์ด์–ธํŠธ, Engine 2. Request 3. Response Request๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ชจ๋“  ํ•จ์ˆ˜(request, get, post, …)๋Š” HttpResponse ๊ฐ์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค. Response body Raw body String val httpResponse: HttpResponse = client.get("https://ktor.io/") val stringBody: String = httpResponse.receive() ByteArray val httpResponse: HttpResponse = client.get("https://ktor.io/") val byteArrayBody: By..

[Ktor] 2. Request

Ktor Client ๊ฐ€์ด๋“œ ์š”์•ฝ ์ •๋ฆฌ Ktor Documents ๊ธฐ์ค€ ๋ฒ„์ „: 1.6.2 ์‹œ๋ฆฌ์ฆˆ 1. ํด๋ผ์ด์–ธํŠธ, Engine 2. Request 3. Response HttpClient์˜ request ํ•จ์ˆ˜๋กœ HTTP Request๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค. request ํ•จ์ˆ˜ ์‹œ๊ทธ๋‹ˆ์ฒ˜ - ๋Œ€ํ‘œ์ ์ธ ์˜ˆ์‹œ inline suspend fun HttpClient.request(urlString: String, block: HttpRequestBuilder.() -> Unit = {}): T inline suspend fun HttpClient.request(builder: HttpRequestBuilder = HttpRequestBuilder()): T ์ด์™ธ ๋ชจ๋“  ํ•จ์ˆ˜ ์‹œ๊ทธ๋‹ˆ์ฒ˜๋Š” ์—ฌ๊ธฐ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. Http..

[Ktor] 1. ํด๋ผ์ด์–ธํŠธ, Engine

Ktor Client ๊ฐ€์ด๋“œ ์š”์•ฝ ์ •๋ฆฌ Ktor Documents ๊ธฐ์ค€ ๋ฒ„์ „: 1.6.2 ์‹œ๋ฆฌ์ฆˆ 1. ํด๋ผ์ด์–ธํŠธ, Engine 2. Request 3. Response Engine Ktor HTTP ํด๋ผ์ด์–ธํŠธ๋Š” JVM, Android, JS, Native(iOS/desktop)๊ณผ ๊ฐ™์ด ๋‹ค๋ฅธ ํ”Œ๋žซํผ์—์„œ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ๋‹ค. ํŠน์ • ํ”Œ๋žซํผ์—์„œ ๋„คํŠธ์›Œํฌ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ํŠน์ • engine์ด ํ•„์š”ํ•  ์ˆ˜๋„ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, Android์—์„œ๋Š” OkHttp๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  JVM์—์„œ๋Š” Apache๋‚˜ CIO๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ktor-client-core ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์™ธ์— ๊ฐ ํ”Œ๋žซํผ์—์„œ ์‚ฌ์šฉํ•  engine์— ๋Œ€ํ•œ ๋””ํŽœ๋˜์‹œ๋Š” ๋ณ„๋„๋กœ ์ถ”๊ฐ€ํ•ด์ค˜์•ผ ํ•œ๋‹ค. Engine dependency ๊ฐ€์ด๋“œ์—์„œ ํ”Œ๋žซํผ ๋ณ„ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ engi..