OpenFeign / OpenFeign/feign

Using feign with multiple possible 20x codes

Open
#2,461 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feedback provided
Dominant language
Java
Stars
9.8k
Forks
1.9k
Avg merge
1d 2h
Merged PRs (30d)
41

Description

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

while the feign builder gets:

decoder = JacksonDecoderWithStatus<EmptyResponse>()

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin with the shown JacksonDecoderWithStatus and Feign builder decoder configuration, then inspect how the client exposes response status and empty bodies. No repository file or test is named, so completion criteria would need maintainer guidance on the supported API for distinguishing 200 from 202.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.