org.jetbrains.kotlinx.jupyter.common.RequestBuilder.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-jupyter-script-classpath-shadowed Show documentation
Show all versions of kotlin-jupyter-script-classpath-shadowed Show documentation
Kotlin Jupyter kernel script classpath with all dependencies inside one artifact
package org.jetbrains.kotlinx.jupyter.common
class RequestBuilder {
private var method: String = ""
private var url: String = ""
private val headers: MutableMap = mutableMapOf()
private var body: String? = null
fun method(method: String) = apply { this.method = method }
fun url(url: String) = apply { this.url = url }
fun header(
name: String,
value: String,
) = apply { this.headers[name] = value }
fun body(body: String?) = apply { this.body = body }
fun build(): Request = RequestImpl(method, url, headers, body)
}
fun buildRequest(buildAction: RequestBuilder.() -> Unit): Request {
return RequestBuilder()
.apply(buildAction)
.build()
}
fun buildRequest(
method: String,
url: String,
headers: Map = mapOf(),
body: String? = null,
buildAction: RequestBuilder.() -> Unit = {},
): Request {
return buildRequest {
method(method)
url(url)
for ((key, value) in headers) {
header(key, value)
}
body(body)
buildAction()
}
}
fun buildRequest(
request: Request,
buildAction: RequestBuilder.() -> Unit,
): Request {
return buildRequest(
request.method,
request.url,
request.headers,
request.body,
buildAction,
)
}
private class RequestImpl(
override val method: String,
override val url: String,
override val headers: Map,
override val body: String?,
) : Request
© 2015 - 2025 Weber Informatics LLC | Privacy Policy