Closed
Description
It would be nice if http interface clients had support for specifying static headers declaratively on a per method basis. Envisioning something similar to what Retrofit has here.
interface RepositoryService {
// The part to be added
@RequestHeaders({
"X-Foo: Bar",
"X-Ping: Pong"
})
@GetExchange("/repos/{owner}/{repo}")
Repository getRepository(@PathVariable String owner, @PathVariable String repo);
// Other http exchange methods with different defaults...
}
Unless I've missed something, I believe the only two ways to supply headers currently are:
- Via a
@RequestHeader
method parameter. Problem being the value must be provided every time - Via global defaults set on the
WebClient
/RestClient
/RestTemplate
backing the declarative client. Problem being you may not want to have those headers applied to every call, but rather just those on a particular method
HttpExchange already has support for accept
and contentType
, so perhaps a generic array of headers could be accepted there as well