mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-18 14:47:15 +00:00
improvements in query parameters getting
This commit is contained in:
parent
4bbe7e5a80
commit
aa7cc503f2
@ -2,6 +2,10 @@
|
||||
|
||||
## 0.18.0
|
||||
|
||||
* `Ktor`:
|
||||
* `Server`:
|
||||
* Now it is possible to take query parameters as list
|
||||
|
||||
## 0.17.8
|
||||
|
||||
* `Versions`:
|
||||
|
@ -12,10 +12,22 @@ suspend fun ApplicationCall.getParameterOrSendError(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun ApplicationCall.getParametersOrSendError(
|
||||
field: String
|
||||
) = parameters.getAll(field).also {
|
||||
if (it == null) {
|
||||
respond(HttpStatusCode.BadRequest, "Request must contains $field")
|
||||
}
|
||||
}
|
||||
|
||||
fun ApplicationCall.getQueryParameter(
|
||||
field: String
|
||||
) = request.queryParameters[field]
|
||||
|
||||
fun ApplicationCall.getQueryParameters(
|
||||
field: String
|
||||
) = request.queryParameters.getAll(field)
|
||||
|
||||
suspend fun ApplicationCall.getQueryParameterOrSendError(
|
||||
field: String
|
||||
) = getQueryParameter(field).also {
|
||||
@ -23,3 +35,11 @@ suspend fun ApplicationCall.getQueryParameterOrSendError(
|
||||
respond(HttpStatusCode.BadRequest, "Request query parameters must contains $field")
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun ApplicationCall.getQueryParametersOrSendError(
|
||||
field: String
|
||||
) = getQueryParameters(field).also {
|
||||
if (it == null) {
|
||||
respond(HttpStatusCode.BadRequest, "Request query parameters must contains $field")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user