https://kotlinlang.org logo
#ktor
Title
# ktor
s

Stylianos Gakis

02/28/2024, 11:28 PM
Got a ktor client POST request that does not necessarily return anything back, so I can’t check if it went right by trying to deserialize the response, as I am doing in a previous thread here. Is there that I can simply assert that the post request successfully went through? Or is my best bet to simply do a check for
response.status == HttpStatusCode.OK
?
a

Arjan van Wieringen

02/29/2024, 6:39 AM
A statuscode should indicate if a response was good
s

Stylianos Gakis

02/29/2024, 8:18 AM
Yeah figured as much. I was relying on the exception being thrown in all other cases so this would just be a bit different which is why I was wondering if there was any
response.assertSuccessful()
. But the status check is simple enough, thanks for reassuring me 😊
a

Arjan van Wieringen

02/29/2024, 10:23 AM
Please note that this is the convention and the standard. A lot of API's don't adhere to this standard. And GraphQL defines 200 as a succesful graphQL response, even though the response itself can contain an
errors
block.
s

Stylianos Gakis

02/29/2024, 10:33 AM
Yeap, luckily this time I am certain I am not communicating with a GraphQL backend. The backend code for that endpoint is literally just a function returning nothing in a Spring backend context in a class annotated with
@RestController
Copy code
@PostMapping("/{id}/foo")
fun someFunction(@PathVariable id: UUID): Unit {
    someService.sideEffect(id)
}
I would not expect this to return 200 if anything goes bad
2 Views