Provide RequestTemplate.getParams() to access template variables (@Param) within an interceptor
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.8k
- Forks
- 1.9k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 41
Description
It would be nice having a method to access @Param annotated parameters within an Interceptor.
Currently @Param template variables are only applied to header, requestline or the body.
As example this kind of RequestTemplate.getParams() would really help us.
public class MyServce {
private final MyClient client;
public void doSmth() {
// Set the codec to some value. e.g. MP3. The key thing is that only the class "MyService"
// knows which codec to choose.
client.getSomething("MP3");
}
}
public interface MyClient {
// define the template variable "codec".
// codec is not used in RequestLine, Body or Header
@RequestLine("GET /")
Object getSomething(@Param("codec") String codec);
}
public class CodecInterceptor implements RequestInterceptor {
@Override
public void apply(RequestTemplate requestTemplate) {
// use params.get("codec") to get the codec and generate the headers
Map<String, Object> params = requestTemplate.getParams();
// ...
}
}
Since the business logic to detect which "codec" is required, is and should be placed in MyService, there is currently no way to pass this information (in a thread safe manner) to the interceptor. If there would be a RequestTemplate.getParams(), the business logic to detect the codec could stay in MyService and the logic to translate the codec into headers could be done within the interceptor.
That would help to accomplish separation of concerns (Service=BusinessLogic, Interceptor=HttpMagic).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the RequestTemplate and RequestInterceptor entry points and how @Param values are currently applied to request headers, request lines, or bodies. Determine how template variables can remain available to the interceptor without compromising request isolation. Done means an interceptor can access the example codec value and existing request-template behavior remains covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100