Skip to content

Support static headers for http interface clients #33309

Closed
@hesselapplications

Description

@hesselapplications

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

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions