Hey there! If I have a ktor client and some sealed...
# ktor
a
Hey there! If I have a ktor client and some sealed class
Foo
that has
Bar
and
Baz
as subclasses, and I make a post request that can either create a
Bar
or a
Baz
, how can I do that? Do I say
<http://myClient.post|myClient.post><Foo> { … }
and then process the entity as either
Bar
or
Baz
?
Copy code
val response = client.request<HttpResponse>("<https://example.com>")
if (response.status == HttpStatusCode.OK) {
    response.receive<SuccessResponse>()
} else {
    response.receive<ErrorResponse>()
}
d
Or use a when statement
Copy code
when(val response = client.request<HttpResponse>("<https://example.com>")) {
 is SuccessResponse -> ... do success stuff
 is ErrorResponse -> ... do error stuff
}
👀 1