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
Single<Pet> save(String name, int age);
@Get("/{name}")
Single<Pet> get(String name);
}
Defining Headers via Configuration
@Client("/pets")
@Header(name="X-Pet-Client", value='${pet.client.id}')
interface PetClient extends PetOperations {
@Override
Single<Pet> save(String name, int age)
@Get("/{name}")
Single<Pet> get(String name)
}
Defining Headers via Configuration
@Client("/pets")
@Header(name = "X-Pet-Client", value = "\${pet.client.id}")
interface PetClient : PetOperations {
override fun save(name: String, age: Int): Single<Pet>
@Get("/{name}")
operator fun get(name: String): Single<Pet>
}
The above example defines a @Header annotation on the PetClient
interface that reads a property using property placeholder configuration called pet.client.id
.
In your application configuration you 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.