Using Feign 11.9.1 ... (yes - a bit old I know ...)
I have an API that I can't change that returns either 200 or 202 depending on what happens on the backend. Client needs to know which response status code was returned. Body will always be empty.
What is the best way to handle this? (Using feign/kotlin)
Currently - I have something super hacky (i'm not proude of this) working - Client side I have a definition using:
@RequestLine("PUT /some/rando/api")
fun callRandoApi(
@RequestBody request: RandoRequest,
): Response<EmptyResponse>
where:
class EmptyResponse // this models an empty body just fine I guess
data class Response<T>(val status: Int, val body: T) // models passing the response code back always
and a custom decoder:
class JacksonDecoderWithStatus<T> : JacksonDecoder() {
override fun decode(response: feign.Response, type: Type): Response<T> {
// use the inner type
val innerType: Type = (type as ParameterizedTypeImpl).actualTypeArguments.first() // yuck
@Suppress("UNCHECKED_CAST")
return Response(
status = response.status(),
body = super.decode(response, innerType) as T, // somewhat - gross
)
}
}
I realize that nothing really connects the decoder type to the response inner type and I don't like using the reflect stuff directly ... ; I have a inline reified function I was playing with as well ..
It seems like there should be a more straightforward way to do this ... Am I wrong?
Using Feign 11.9.1 ... (yes - a bit old I know ...)
I have an API that I can't change that returns either 200 or 202 depending on what happens on the backend. Client needs to know which response status code was returned. Body will always be empty.
What is the best way to handle this? (Using feign/kotlin)
Currently - I have something super hacky (i'm not proude of this) working - Client side I have a definition using:
where:
and a custom decoder:
while the feign builder gets:
I realize that nothing really connects the decoder type to the response inner type and I don't like using the reflect stuff directly ... ; I have a inline reified function I was playing with as well ..
It seems like there should be a more straightforward way to do this ... Am I wrong?