KtorClient

class KtorClient(val hostName: String) : Closeable

An HTTP client with some easy to use methods ready to send and receive data in JSON format via Configuration.json. All methods can throw exception if the HttpStatusCode is not ok

Notes:

  • hostName cannot contain the URL scheme/protocol, which is defined in DefaultRequest block

  • QueryParams cannot be in the path when calling get, post, etc. They need to be specially encoded by Ktor at withUrl

  • Consider using close when closing the app

  • Maybe todo: Support streaming responses

    • https://ktor.io/docs/client-responses.html#streaming

    • https://ai.google.dev/api/generate-content#method:-models.streamgeneratecontent

Constructors

Link copied to clipboard
constructor(hostName: String)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
private val hostName: String
Link copied to clipboard
private val httpClient: HttpClient

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
suspend fun get(path: String, queryParams: QueryParams = emptyList(), headers: Headers = headers {}): HttpResponse
Link copied to clipboard
suspend fun post(path: String, queryParams: QueryParams = emptyList(), body: Any, headers: Headers = headers {}): HttpResponse
Link copied to clipboard
private fun HttpRequestBuilder.withUrl(path: String, queryParams: QueryParams = emptyList(), extraConfig: URLBuilder.() -> Unit = {})

Util function that should be common to all HTTP-method functions