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: 1. Via a @RequestHeader method parameter. Problem being the value must be provided every time 2. 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

Comment From: simonbasle

The @HttpExchange route sounds like a good one. For clients, we can support simple header name-value pairs for each array entry. On the server side, this can be more flexible as this could be translated to a HeadersMappingCondition, similar to what's done with @RequestMapping#headers().