improvements in query parameters getting

This commit is contained in:
InsanusMokrassar 2023-04-25 13:14:12 +06:00
parent 4bbe7e5a80
commit aa7cc503f2
2 changed files with 24 additions and 0 deletions

View File

@ -2,6 +2,10 @@
## 0.18.0
* `Ktor`:
* `Server`:
* Now it is possible to take query parameters as list
## 0.17.8
* `Versions`:

View File

@ -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")
}
}