public final class RequestTemplate extends Object implements Serializable
This class is a variation on a UriTemplate, where, in addition to the uri, Headers and Query information also support template expressions.
Constructor and Description |
---|
RequestTemplate()
Create a new Request Template.
|
RequestTemplate(RequestTemplate toCopy)
Deprecated.
replaced by
from(RequestTemplate) |
Modifier and Type | Method and Description |
---|---|
RequestTemplate |
append(CharSequence value)
Deprecated.
|
byte[] |
body()
The Request Body.
|
RequestTemplate |
body(byte[] data,
Charset charset)
Sets the Body and Charset for this request.
|
RequestTemplate |
body(Request.Body body)
Deprecated.
use
body(byte[], Charset) instead. |
RequestTemplate |
body(String bodyText)
Set the Body for this request.
|
String |
bodyTemplate()
Body Template to resolve.
|
RequestTemplate |
bodyTemplate(String bodyTemplate)
Specify the Body Template to use.
|
RequestTemplate |
bodyTemplate(String bodyTemplate,
Charset charset)
Specify the Body Template to use.
|
CollectionFormat |
collectionFormat()
The Collection Format that will be used when resolving
Iterable and Collection
variables. |
RequestTemplate |
collectionFormat(CollectionFormat collectionFormat)
The Collection Format to use when resolving variables that represent
Iterable s or
Collection s |
boolean |
decodeSlash()
If slash / characters are not encoded when resolving.
|
RequestTemplate |
decodeSlash(boolean decodeSlash)
Set whether do encode slash / characters when resolving this template.
|
Target<?> |
feignTarget() |
RequestTemplate |
feignTarget(Target<?> feignTarget) |
static RequestTemplate |
from(RequestTemplate requestTemplate)
Create a Request Template from an existing Request Template.
|
Collection<String> |
getRequestVariables()
Retrieve all uri, header, and query template variables.
|
boolean |
hasRequestVariable(String variable)
Return if the variable exists on the uri, query, or headers, in this template.
|
RequestTemplate |
header(String name,
Iterable<String> values)
Specify a Header, with the specified values.
|
RequestTemplate |
header(String name,
String... values) |
Map<String,Collection<String>> |
headers()
Returns an immutable copy of the Headers for this request.
|
RequestTemplate |
headers(Map<String,Collection<String>> headers)
Headers for this Request.
|
RequestTemplate |
insert(int pos,
CharSequence value)
Deprecated.
see
target(String) |
String |
method()
The Request Http Method.
|
RequestTemplate |
method(Request.HttpMethod method)
Set the Http Method.
|
RequestTemplate |
method(String method)
Deprecated.
see
RequestTemplate#method(HttpMethod) |
MethodMetadata |
methodMetadata() |
RequestTemplate |
methodMetadata(MethodMetadata methodMetadata) |
String |
path()
The Uri Path.
|
Map<String,Collection<String>> |
queries()
Return an immutable Map of all Query Parameters and their values.
|
RequestTemplate |
queries(Map<String,Collection<String>> queries)
Sets the Query Parameters.
|
RequestTemplate |
query(String name,
Iterable<String> values)
Specify a Query String parameter, with the specified values.
|
RequestTemplate |
query(String name,
Iterable<String> values,
CollectionFormat collectionFormat)
Specify a Query String parameter, with the specified values.
|
RequestTemplate |
query(String name,
String... values) |
String |
queryLine()
The Query String for the template.
|
RequestTemplate |
removeHeader(String name)
Clear on reader from
RequestTemplate |
Request |
request()
Creates a
Request from this template. |
Request.Body |
requestBody()
Deprecated.
this abstraction is leaky and will be removed in later releases.
|
Charset |
requestCharset()
Charset of the Request Body, if known.
|
RequestTemplate |
resolve(Map<String,?> variables)
Resolve all expressions using the variable value substitutions provided.
|
boolean |
resolved()
If this template has been resolved.
|
RequestTemplate |
target(String target)
Set the target host for this request.
|
String |
toString() |
RequestTemplate |
uri(String uri)
Set the Uri for the request, replacing the existing uri if set.
|
RequestTemplate |
uri(String uri,
boolean append)
Set the uri for the request.
|
String |
url()
The URL for the request.
|
List<String> |
variables()
List all of the template variable expressions for this template.
|
public RequestTemplate()
@Deprecated public RequestTemplate(RequestTemplate toCopy)
from(RequestTemplate)
toCopy
- template.public static RequestTemplate from(RequestTemplate requestTemplate)
requestTemplate
- to copy from.public RequestTemplate resolve(Map<String,?> variables)
variables
- containing the variable values to use when resolving expressions.public Request request()
Request
from this template. The template must be resolved before calling this
method, or an IllegalStateException
will be thrown.IllegalStateException
- if this template has not been resolved.@Deprecated public RequestTemplate method(String method)
RequestTemplate#method(HttpMethod)
method
- to use.public RequestTemplate method(Request.HttpMethod method)
method
- to use.public String method()
public RequestTemplate decodeSlash(boolean decodeSlash)
decodeSlash
- if slash literals should not be encoded.public boolean decodeSlash()
public RequestTemplate collectionFormat(CollectionFormat collectionFormat)
Iterable
s or
Collection
scollectionFormat
- to use.public CollectionFormat collectionFormat()
Iterable
and Collection
variables.@Deprecated public RequestTemplate append(CharSequence value)
uri(String, boolean)
This method is poorly named and is used primarily to store the relative uri for the request. It
has been replaced by uri(String)
and will be removed in a future
release.
value
- to append.@Deprecated public RequestTemplate insert(int pos, CharSequence value)
target(String)
This method is poorly named has undocumented behavior. When the value contains a fully qualified http request url, the value is always inserted at the beginning of the uri.
Due to this, use of this method is not recommended and remains for backward compatibility. It
has been replaced by target(String)
and will be removed in a future
release.
pos
- in the uri to place the value.value
- to insert.public RequestTemplate uri(String uri)
uri
- to use, must be a relative uri.public RequestTemplate uri(String uri, boolean append)
uri
- to use, must be a relative uri.append
- if the uri should be appended, if the uri is already set.public RequestTemplate target(String target)
target
- host for this request. Must be an absolute target.public String url()
public String path()
public List<String> variables()
public RequestTemplate query(String name, String... values)
query(String, Iterable)
public RequestTemplate query(String name, Iterable<String> values)
name
- of the parameter.values
- for this parameter.public RequestTemplate query(String name, Iterable<String> values, CollectionFormat collectionFormat)
name
- of the parameter.values
- for this parameter.collectionFormat
- to use when resolving collection based expressions.public RequestTemplate queries(Map<String,Collection<String>> queries)
queries
- to use for this request.public Map<String,Collection<String>> queries()
public RequestTemplate header(String name, String... values)
header(String, Iterable)
public RequestTemplate header(String name, Iterable<String> values)
name
- of the header.values
- for this header.public RequestTemplate removeHeader(String name)
RequestTemplate
name
- of the header.public RequestTemplate headers(Map<String,Collection<String>> headers)
headers
- to use.public Map<String,Collection<String>> headers()
public RequestTemplate body(byte[] data, Charset charset)
data
- to send, can be null.charset
- of the encoded data.public RequestTemplate body(String bodyText)
bodyText
- to send.@Deprecated public RequestTemplate body(Request.Body body)
body(byte[], Charset)
instead.body
- to send.public Charset requestCharset()
public byte[] body()
@Deprecated public Request.Body requestBody()
public RequestTemplate bodyTemplate(String bodyTemplate)
bodyTemplate
- to use.public RequestTemplate bodyTemplate(String bodyTemplate, Charset charset)
bodyTemplate
- to use.public String bodyTemplate()
public boolean hasRequestVariable(String variable)
variable
- to look for.public Collection<String> getRequestVariables()
public boolean resolved()
public String queryLine()
@Experimental public RequestTemplate methodMetadata(MethodMetadata methodMetadata)
@Experimental public RequestTemplate feignTarget(Target<?> feignTarget)
@Experimental public MethodMetadata methodMetadata()
@Experimental public Target<?> feignTarget()
Copyright © 2012–2020 OpenFeign. All rights reserved.