RequestTemplate class
A Feign request that is about to be sent, still open to changes.
A RequestInterceptor receives it to change what every call sends: the URL, the headers, the body. It is built from the method's mapping and the call's arguments; once the interceptors ran, the configured default headers and query parameters are added and the request is sent. Every attempt of a call, retries included, starts from a new template, so changes never pile up.
header and query add a value, as in Feign; to replace a header,
remove it first (or call headers.set).
// In an interceptor: a request id, the language, and a fresh token
// instead of whatever the call carried.
template
..header('X-Request-Id', uuid())
..query('lang', 'en')
..removeHeader('Authorization')
..header('Authorization', 'Bearer $token');
Spring (Java):
template.header("X-Request-Id", uuid()).query("lang", "en")
.removeHeader("Authorization")
.header("Authorization", "Bearer " + token);
Constructors
-
RequestTemplate({required HttpMethod method, required Uri url, required String methodKey, required String clientName, HttpHeaders? headers, List<
int> ? body}) -
A request of
methodtourl, made by the methodmethodKeyof the clientclientName, with no headers and no body unless given. The client creates templates; interceptors receive them.
Properties
-
body
↔ List<
int> ? -
The encoded body, or
nullfor none. Replacing it does not change theContent-Typeheader.getter/setter pair - clientName → String
-
The client's
@FeignClientname, such ascatalog; an interceptor shared by all clients checks it to act on some only.final - hashCode → int
-
The hash code for this object.
no setterinherited
- headers → HttpHeaders
-
The request headers, to read or change.
final
- method ↔ HttpMethod
-
The HTTP method; an interceptor may change it.
getter/setter pair
- methodKey → String
-
Which method of which client makes the call, such as
CatalogClient#find(String); error decoders get the same key.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- url ↔ Uri
-
The full URL, base URL, path and query included; an interceptor may
replace it.
getter/setter pair
Methods
-
header(
String name, String value) → void -
Adds
valueto the values of the headername, keeping those already there, as Feign'sheader(name, values...)does. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
query(
String name, String value) → void -
Adds the query parameter
namewithvalueat the end of url, encoded as in a form (+for a space); the query already in url stays as written, and a parameter of that name is not replaced. -
removeHeader(
String name) → void -
Removes every value of the header
name, as Feign'sremoveHeaderdoes. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited