feign icon indicating copy to clipboard operation
feign copied to clipboard

New Feature: Support for variable contexts on URIs

Open pkordis-r7 opened this issue 4 years ago • 1 comments

It would be nice if via an annotation at class or method level, there could be a means of specifying an implentation that could supply dynamic values to contexts. Consider the following examples:

@VariableContext(alias = "varCtx", supplier = TheValueSupplier.class)
public class Example {

    @Headers({
        "accept: application/json",
    })
    @RequestLine("GET /api/{varCtx}/someEntity/{id}")
    SomeEntity getById(@Param("id") Long id);

}

As it is obvious, the {varCtx} does not need to be passed explicitely via the method's argument. It would also be nice to give the same annotation precedence if placed over a method while one is marking the enclosing class too.

I think this is very handy for cases where a dynamic switch of APIs is needed e.g. between versions (/api/v1/my/path to /api/v2/my/path) or other circumstances (/api/my/path to /api/session/my/path)

pkordis-r7 avatar Jan 28 '21 15:01 pkordis-r7

My "hot take" on this. This is very specific. We already support dynamic URI resolution using method parameters, request interceptors, and the ability for your to define your own Target implementation for this type of just-in-time resolution.

For example, you can build a ContextAware RequestInterceptor where you can directly manipulate the uri.

Regardless, we'll mark this as a proposal and let others provide more feedback. If this receives enough votes, we will consider it.

kdavisk6 avatar Feb 03 '21 04:02 kdavisk6