def http = HttpBuilder.configure {
request.uri = 'http://localhost:10101'
request.contentType = 'text/json'
}
http.post {
request.uri.path = '/bar'
request.contentType = 'text/csv'
}
public static interface HttpConfig.Request
Defines the configurable HTTP request properties.
The uri
property is the only one that must be defined either in the HttpBuilder
or in the verb configuration.
Modifier and Type | Method and Description |
---|---|
default void |
cookie(java.lang.String name,
java.lang.String value)
The
cookie configuration options provide a means of adding HTTP Cookies to the request. |
void |
cookie(java.lang.String name,
java.lang.String value,
java.util.Date expires)
The
cookie configuration options provide a means of adding HTTP Cookies to the request. |
void |
cookie(java.lang.String name,
java.lang.String value,
java.time.LocalDateTime expires)
The
cookie configuration options provide a means of adding HTTP Cookies to the request. |
void |
encoder(java.lang.Iterable<java.lang.String> contentTypes,
java.util.function.BiConsumer<ChainedHttpConfig,ToServer> val)
Specifies the request encoder (
ToServer instance) to be used when encoding the given list of content types. |
java.util.function.BiConsumer<ChainedHttpConfig,ToServer> |
encoder(java.lang.String contentType)
Retrieves the request encoder (
ToServer instance) for the specified content type wrapped in a BiConsumer function. |
void |
encoder(java.lang.String contentType,
java.util.function.BiConsumer<ChainedHttpConfig,ToServer> val)
Specifies the request encoder (
ToServer instance) to be used when encoding the given content type. |
HttpConfig.Auth |
getAuth()
Retrieves the authentication information for the request.
|
java.util.Map<java.lang.String,java.lang.CharSequence> |
getHeaders()
Used to retrieve the request headers.
|
UriBuilder |
getUri()
Retrieves the
UriBuilder for the request, which provides methods for more fine-grained URI specification. |
void |
setAccept(java.lang.Iterable<java.lang.String> values)
The
accept property allows configuration of the request Accept header, which may be used to specify certain media types which are
acceptable for the response. |
void |
setAccept(java.lang.String[] values)
The
accept property allows configuration of the request Accept header, which may be used to specify certain media types which are
acceptable for the response. |
void |
setBody(java.lang.Object val)
The
body property is used to configure the body content for the request. |
void |
setCharset(java.nio.charset.Charset val)
The
charset property is used to specify the character set (as a Charset ) used by the request. |
void |
setCharset(java.lang.String val)
The
charset property is used to specify the character set (as a String) used by the request. |
void |
setContentType(java.lang.String val)
The
contentType property is used to specify the Content-Type header value for the request. |
void |
setHeaders(java.util.Map<java.lang.String,java.lang.CharSequence> toAdd)
The
headers property allows the direct specification of the request headers as a Map<String,String> . |
void |
setRaw(java.lang.String val)
The
request.raw is the means of specifying a "raw" URI as the HTTP endpoint for the request, specified as a String . |
void |
setUri(java.lang.String val)
The
request.uri is the URI of the HTTP endpoint for the request, specified as a String in this case. |
void |
setUri(java.net.URI val)
The
request.uri is the URI of the HTTP endpoint for the request, specified as a URI in this case. |
void |
setUri(java.net.URL val)
The
request.uri is the URI of the HTTP endpoint for the request, specified as a URL in this case. |
HttpConfig.Auth getAuth()
Retrieves the authentication information for the request.
void setContentType(java.lang.String val)
The contentType
property is used to specify the Content-Type
header value for the request.
def http = HttpBuilder.configure {
request.uri = 'http://localhost:10101'
request.contentType = 'text/json'
}
http.post {
request.uri.path = '/bar'
request.contentType = 'text/csv'
}
By default, the value will be text/plain
. The ContentTypes
class provides a helper for some of the more common content type values.
val
- the content type value to be usedvoid setCharset(java.lang.String val)
The charset
property is used to specify the character set (as a String) used by the request.
def http = HttpBuilder.configure {
request.uri = 'http://localhost:10101'
request.charset = 'utf-16'
}
http.post {
request.uri.path = '/bar'
request.charset = 'utf-8'
}
val
- the content type character set value to be usedvoid setCharset(java.nio.charset.Charset val)
The charset
property is used to specify the character set (as a Charset
) used by the request. This value will be reflected in
the Content-Type
header value (e.g. Content-Type: text/plain; charset=utf-8
). A content-type value must be specified in order for this
value to be applied.
def http = HttpBuilder.configure {
request.uri = 'http://localhost:10101'
request.charset = 'utf-16'
}
http.post {
request.uri.path = '/bar'
request.charset = 'utf-8'
}
val
- the content type character set value to be usedUriBuilder getUri()
Retrieves the UriBuilder
for the request, which provides methods for more fine-grained URI specification.
def http = HttpBuilder.configure {
request.uri = 'http://localhost:10101'
}
http.get {
request.uri.path = '/foo'
}
UriBuilder
for the requestvoid setUri(java.lang.String val)
The request.uri
is the URI of the HTTP endpoint for the request, specified as a String
in this case.
def http = HttpBuilder.configure {
request.uri = 'http://localhost:10101'
}
http.get {
request.uri.path = '/foo'
}
http.post {
request.uri.path = '/bar'
}
Which allows multiple verb requests to be configured against the same HttpBuilder
. See the UriBuilder
documentation for
more details.
The uri
is the only required configuration property.
val
- the URI to be used for the request, as a Stringjava.lang.IllegalArgumentException
- if there is a problem with the URI syntaxvoid setRaw(java.lang.String val)
The request.raw
is the means of specifying a "raw" URI as the HTTP endpoint for the request, specified as a String
. No encoding or decoding is performed on a "raw" URI. Any such
encoding or decoding of URI content must be done in the provided string itself, as it will be used "as is" in the resulting URI. This functionality is useful in the case where
there are encoded entities in the URI path, since the standard uri
method will decode these on building the URI
.
val
- the raw URI stringvoid setUri(java.net.URI val)
The request.uri
is the URI of the HTTP endpoint for the request, specified as a URI
in this case.
def http = HttpBuilder.configure {
request.uri = new URI('http://localhost:10101')
}
http.get {
request.uri.path = '/foo'
}
http.post {
request.uri.path = '/bar'
}
Which allows multiple verb requests to be configured against the same HttpBuilder
. See the UriBuilder
documentation for
more details.
The uri
is the only required configuration property.
val
- the URI to be used for the request, as a URIvoid setUri(java.net.URL val) throws java.net.URISyntaxException
The request.uri
is the URI of the HTTP endpoint for the request, specified as a URL
in this case.
def http = HttpBuilder.configure {
request.uri = new URL('http://localhost:10101')
}
http.get {
request.uri.path = '/foo'
}
http.post {
request.uri.path = '/bar'
}
Which allows multiple verb requests to be configured against the same HttpBuilder
. See the UriBuilder
documentation for
more details.
The uri
is the only required configuration property.
val
- the URI to be used for the request, as a URLjava.net.URISyntaxException
java.util.Map<java.lang.String,java.lang.CharSequence> getHeaders()
Used to retrieve the request headers.
Map
of request headersvoid setHeaders(java.util.Map<java.lang.String,java.lang.CharSequence> toAdd)
The headers
property allows the direct specification of the request headers as a Map<String,String>
. Be aware that Content-Type
and
Accept
are actually header values and it is up to the implementation to determine which configuration will win out if both are configured.
def http = HttpBuilder.configure {
request.uri = 'http://localhost:10101'
request.headers = [
ClientId: '987sdfsdf9uh'
]
}
http.post {
request.uri.path = '/bar'
request.headers = [
AccessCode: '99887766'
]
}
Warning
|
The headers are additive; however, a header specified in the verb configuration may overwrite one defined in the global configuration. |
toAdd
- the headers to be added to the request headersvoid setAccept(java.lang.String[] values)
The accept
property allows configuration of the request Accept
header, which may be used to specify certain media types which are
acceptable for the response.
def http = HttpBuilder.configure {
request.uri = 'http://localhost:10101'
request.accept = ['image/jpeg']
}
http.post {
request.uri.path = '/bar'
request.accept = ['image/tiff', 'image/png']
}
values
- the accept header values as a String arrayvoid setAccept(java.lang.Iterable<java.lang.String> values)
The accept
property allows configuration of the request Accept
header, which may be used to specify certain media types which are
acceptable for the response.
def http = HttpBuilder.configure {
request.uri = 'http://localhost:10101'
request.accept = ['image/jpeg']
}
http.post {
request.uri.path = '/bar'
request.accept = ['image/tiff', 'image/png']
}
values
- the accept header values as a Listvoid setBody(java.lang.Object val)
The body
property is used to configure the body content for the request. The request body content may be altered by configured encoders
internally or may be passed on unmodified. See HttpConfig
and HttpObjectConfig
for content-altering methods (encoders,
decoders and interceptors).
val
- the request body contentdefault void cookie(java.lang.String name, java.lang.String value)
The cookie
configuration options provide a means of adding HTTP Cookies to the request. Cookies are defined with a name
and value
.
def http = HttpBuilder.configure {
request.uri = 'http://localhost:10101'
request.cookie 'seen-before', 'true'
}
Warning
|
Cookies are additive, once a Cookie is defined (e.g. in the global configuration), you cannot overwrite it in per-verb configurations. |
As noted in the HttpObjectConfig.Client
configuration, the default Cookie version supported is 0
, but this may
be modified.
name
- the cookie namevalue
- the cookie valuevoid cookie(java.lang.String name, java.lang.String value, java.util.Date expires)
The cookie
configuration options provide a means of adding HTTP Cookies to the request. Cookies are defined with a name
, value
, and
expires
Date.
def http = HttpBuilder.configure {
request.uri = 'http://localhost:10101'
request.cookie 'seen-before', 'true'
}
http.post {
request.uri.path = '/bar'
request.cookie 'last-page', 'item-list', Date.parse('MM/dd/yyyy', '12/31/2016')
}
Warning
|
Cookies are additive, once a Cookie is defined (e.g. in the global configuration), you cannot overwrite it in per-verb configurations. |
As noted in the HttpObjectConfig.Client
configuration, the default Cookie version supported is 0
, but this may
be modified.
name
- the cookie namevalue
- the cookie valueexpires
- the cookie expiration datevoid cookie(java.lang.String name, java.lang.String value, java.time.LocalDateTime expires)
The cookie
configuration options provide a means of adding HTTP Cookies to the request. Cookies are defined with a name
, value
, and
an expiration date as LocalDateTime
.
HttpBuilder.configure {
request.uri = 'http://localhost:10101'
}.post {
request.uri.path = '/bar'
request.cookie 'last-page', 'item-list', LocalDateTime.now().plus(1, ChronoUnit.MONTHS)
}
Warning
|
Cookies are additive, once a Cookie is defined (e.g. in the global configuration), you cannot overwrite it in per-verb configurations. |
As noted in the HttpObjectConfig.Client
configuration, the default Cookie version supported is 0
, but this may
be modified.
name
- the cookie namevalue
- the cookie valueexpires
- the cookie expiration datevoid encoder(java.lang.String contentType, java.util.function.BiConsumer<ChainedHttpConfig,ToServer> val)
Specifies the request encoder (ToServer
instance) to be used when encoding the given content type.
contentType
- the content typeval
- the request encoder (wrapped in a BiConsumer
function)void encoder(java.lang.Iterable<java.lang.String> contentTypes, java.util.function.BiConsumer<ChainedHttpConfig,ToServer> val)
Specifies the request encoder (ToServer
instance) to be used when encoding the given list of content types.
contentTypes
- the content typesval
- the request encoder (wrapped in a BiConsumer
function)java.util.function.BiConsumer<ChainedHttpConfig,ToServer> encoder(java.lang.String contentType)
Retrieves the request encoder (ToServer
instance) for the specified content type wrapped in a BiConsumer
function.
contentType
- the content type of the encoder to be retrievedBiConsumer
function)