Populating Headers Using Configuration
The @Header annotation can be declared at the type level and is repeatable such that it is possible to drive the request headers sent via configuration using annotation metadata.
The following example serves to illustrate this:
Defining Headers via Configuration
@Client("/pets")
@Header(name="X-Pet-Client", value="${pet.client.id}")
public interface PetClient extends PetOperations {
@Override
@SingleResult
Publisher<Pet> save(String name, int age);
@Get("/{name}")
@SingleResult
Publisher<Pet> get(String name);
}
Defining Headers via Configuration
@Client("/pets")
@Header(name="X-Pet-Client", value='${pet.client.id}')
interface PetClient extends PetOperations {
@Override
@SingleResult
Publisher<Pet> save(@NotBlank String name, @Min(1L) int age)
@Get("/{name}")
@SingleResult
Publisher<Pet> get(String name)
}
Defining Headers via Configuration
@Client("/pets")
@Header(name = "X-Pet-Client", value = "\${pet.client.id}")
interface PetClient : PetOperations {
@SingleResult
override fun save(name: String, age: Int): Publisher<Pet>
@Get("/{name}")
@SingleResult
operator fun get(name: String): Publisher<Pet>
}
The above example defines a @Header annotation on the PetClient
interface that reads the pet.client.id
property using property placeholder configuration.
Then set the following in application.yml
to populate the value:
Configuring Headers in YAML
pet:
client:
id: foo
Alternatively you can supply a PET_CLIENT_ID
environment variable and the value will be populated.