Request Parts
Per-client or per-request HTTP parts (headers, query/form data, path parameters) can be manipulated via the following methods that return back builders for those parts:
Convenience methods are also provided for quickly adding parts:
// Create a client that adds a "Foo: bar" header to every request.
RestClient client = RestClient.create().header("Foo","bar").build();
// Or do it on every request.
String response = client.get(URI).header("Foo","bar").run().getContent().asString();
The supplier methods are particularly useful for header values whose values may change over time (such as
Authorization headers
which may need to change every few minutes).
// Create a client that adds a dynamic Authorization header to every request.
RestClient client = RestClient.create().header("Authorization", ()->getMyAuthToken()).build();
- org.apache.juneau.http.header - Predefined Header beans.
Constant Parts on Remote-Proxy Interfaces
The above methods add parts on a per-client or per-request basis. When using the next-generation
remote-proxy engine (RestClient.remote(...)), you can also declare
always-applied constant headers, query parameters, and form-data fields directly on the proxy
annotations — with no corresponding method parameter:
- Interface-level:
@Remote(headers=…, queryData=…, formData=…)— applied to every method. - Method-level:
@RemoteOp(headers=…, queryData=…, formData=…)(and the verb annotations) — applied to that method, taking precedence over an interface-level constant of the same name.
@Remote(path="/api", queryData="api_key=$S{petstore.apiKey}")
public interface PetStore {
@RemoteGet(path="/pets", headers="X-View: full", queryData="view=full")
Pet[] getPets();
}
These constants are honored by the next-gen engine only; the classic getRemote(...) engine ignores
them. See
NG Remote Proxies for the full
contract (precedence, VarResolver support, and composition with caller-supplied values).