mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
add query params docs
This commit is contained in:
parent
55aacb8753
commit
b2fc5e2a4d
@ -3,16 +3,28 @@ package dev.inmo.micro_utils.ktor.common
|
||||
typealias QueryParam = Pair<String, String?>
|
||||
typealias QueryParams = Map<String, String?>
|
||||
|
||||
/**
|
||||
* Create query part which includes key=value pairs separated with &
|
||||
*/
|
||||
val QueryParams.asUrlQuery: String
|
||||
get() = keys.joinToString("&") { "${it}${get(it) ?.let { value -> "=$value" }}" }
|
||||
|
||||
/**
|
||||
* Create query part which includes key=value pairs separated with &
|
||||
*/
|
||||
val List<QueryParam>.asUrlQuery: String
|
||||
get() = joinToString("&") { (key, value) -> "${key}${value ?.let { _ -> "=$value" }}" }
|
||||
|
||||
/**
|
||||
* Create query part which includes key=value pairs separated with & and attach to receiver
|
||||
*/
|
||||
fun String.includeQueryParams(
|
||||
queryParams: QueryParams
|
||||
): String = "$this${if(queryParams.isNotEmpty()) "${if (contains("?")) "&" else "?"}${queryParams.asUrlQuery}" else ""}"
|
||||
|
||||
/**
|
||||
* Create query part which includes key=value pairs separated with & and attach to receiver
|
||||
*/
|
||||
fun String.includeQueryParams(
|
||||
queryParams: List<QueryParam>
|
||||
): String = "$this${if (contains("?")) "&" else "?"}${queryParams.asUrlQuery}"
|
||||
|
Loading…
Reference in New Issue
Block a user