feign
feign copied to clipboard
New Feature: Support for variable contexts on URIs
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
)
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.