Hi! How can I send a 204 No content response witho...
# ktor
m
Hi! How can I send a 204 No content response without content ?
Copy code
call.respond(HttpStatusCode.NoContent, Unit)
I have
{}
in the content.
c
I don’t think you need the second parameter there, HttpStatusCode can be sent by itself for no content
m
☝️ How? because there is either
Copy code
ApplicationCall.respond(status: HttpStatusCode, message: Any)
or
Copy code
ApplicationCall.respond(message: Any)
if you send only HttpStatusCode, the second method will be used and the status will be serialized as response content
m
Yes, the
respond
method doesn’t exist with only the HTTP code as parameter.
m
call.response.status(HttpStatusCode.NoContent)
that’s it, you just access the response object and set values which will be immediately sent to the client. https://ktor.io/docs/responses.html
c
Unless I'm missing something entirely, it does work with
call.respond(HttpStatusCode.NoContent)
directly - there'll be a feature somewhere checking if
message
has a type of
HttpStatusCode
and mutating the response. I'll have a dig later 🙂