Ktor Client
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
Functions
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