Interface HttpRequest
- All Known Implementing Classes:
AbstractHttpRequest
public interface HttpRequest
HTTP request.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAddAccept-Encoding
header with"gzip, deflate"
value.Add header to specify that accept type is"application/json"
.acceptLanguage
(String lang) AddAccept-Language
header.Add header to specify that accept type is"application/xml"
.addAcceptEncoding
(String encoding) AddAccept-Encoding
header.Add cookie to http request.Add cookie to http request.addCsrfToken
(String token) Add CSRF Token to http header (X-Csrf-Token
header).addHeader
(HttpHeader header) Add header.Add header.addIfMatch
(String etag) AddIf-Match
header with expected value.addIfModifiedSince
(Date date) AddIf-Modified-Since
value with expected date (date will be translated as GMT raw).addIfNoneMatch
(String etag) AddIf-None-Match
header with expected value.addIfUnmodifiedSince
(Date date) AddIf-Unmodified-Since
value with expected date (date will be translated as GMT raw).AddOrigin
header.addQueryParam
(String name, String value) Add query parameters: a query parameter is a parameter that will follow the?
character in the request URL.addQueryParams
(HttpParameter parameter, HttpParameter... parameters) Add collection of query parameters: a query parameter is a parameter that will follow the?
character in the request URL.addReferer
(String referer) AddReferer
header.addXHttpMethodOverride
(String method) AddX-Http-Method-Override
value with HTTP verb to override.Add header to specify that content type is"application/x-www-form-urlencoded"
.asJson()
Add header to specify that content type is"application/json"
.asXml()
Add header to specify that content type is"application/xml"
.Most library (such as jQuery) add automatically header named "X-Requested-With" with value "XMLHttpRequest", this method add this header and can be used to simulate ajax call.execute()
Execute request and return http response: execution is synchronous and will block until response is available.Execute request and return http response: execution is synchronous and will block until response is available.Execute request and return http response: execution is synchronous and will block until response is available.Request URL.Return http request method.AddX-Http-Method-Override
value withDELETE
value.Add @{code X-Http-Method-Override} value withPUT
value.setBody
(HttpRequestBody body) Set request body.withUserAgent
(String userAgent) AddUser-Agent
header to http request.
-
Method Details
-
getEndpoint
HttpUrl getEndpoint()Request URL.- Returns:
- The request endpoint.
-
getMethod
HttpMethod getMethod()Return http request method.- Returns:
- Method.
-
addHeader
Add header.- Parameters:
name
- Header name.value
- Header value.- Returns:
- Http request that can be used for chaining.
- Throws:
NullPointerException
- Ifname
orvalue
isnull
.IllegalArgumentException
- ifname
is blank.- See Also:
-
addHeader
Add header.- Parameters:
header
- The header.- Returns:
- Http request that can be used for chaining.
- Throws:
NullPointerException
- Ifheader
isnull
.
-
addQueryParam
Add query parameters: a query parameter is a parameter that will follow the?
character in the request URL.- Parameters:
name
- Parameter name.value
- Parameter value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addQueryParams
Add collection of query parameters: a query parameter is a parameter that will follow the?
character in the request URL.- Parameters:
parameter
- Parameter.parameters
- Optional next parameters.- Returns:
- Http request that can be used for chaining.
- See Also:
-
setBody
Set request body. This method should be used for"POST"
,"PUT"
or"PATCH"
request only, otherwise it will throwUnsupportedOperationException
exception.- Parameters:
body
- Body request.- Returns:
- Http request that can be used for chaining.
- Throws:
UnsupportedOperationException
- If request method does not allow body (i.eGET
,HEAD
orDELETE
).
-
asXmlHttpRequest
HttpRequest asXmlHttpRequest()Most library (such as jQuery) add automatically header named "X-Requested-With" with value "XMLHttpRequest", this method add this header and can be used to simulate ajax call.- Returns:
- Http request that can be used for chaining.
- See Also:
-
asFormUrlEncoded
HttpRequest asFormUrlEncoded()Add header to specify that content type is"application/x-www-form-urlencoded"
.- Returns:
- Http request that can be used for chaining.
- See Also:
-
asJson
HttpRequest asJson()Add header to specify that content type is"application/json"
.- Returns:
- Http request that can be used for chaining.
- See Also:
-
asXml
HttpRequest asXml()Add header to specify that content type is"application/xml"
.- Returns:
- Http request that can be used for chaining.
- See Also:
-
acceptJson
HttpRequest acceptJson()Add header to specify that accept type is"application/json"
.- Returns:
- Http request that can be used for chaining.
- See Also:
-
acceptXml
HttpRequest acceptXml()Add header to specify that accept type is"application/xml"
.- Returns:
- Http request that can be used for chaining.
- See Also:
-
acceptLanguage
AddAccept-Language
header.- Parameters:
lang
- Accepted languages.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addOrigin
AddOrigin
header.- Parameters:
origin
- Origin value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addReferer
AddReferer
header.- Parameters:
referer
- Referer value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addAcceptEncoding
AddAccept-Encoding
header.- Parameters:
encoding
- Encoding value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
acceptGzip
HttpRequest acceptGzip()AddAccept-Encoding
header with"gzip, deflate"
value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
withUserAgent
AddUser-Agent
header to http request.- Parameters:
userAgent
- User-Agent value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addCookie
Add cookie to http request.- Parameters:
cookie
- Cookie.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addCookie
Add cookie to http request.- Parameters:
name
- Cookie name.value
- Cookie value.- Returns:
- Http request that can be used for chaining.
- Throws:
NullPointerException
- Ifname
orvalue
arenull
.IllegalArgumentException
- Ifname
is empty or blank.- See Also:
-
addIfNoneMatch
AddIf-None-Match
header with expected value. This header should work withETag
header sent by server response.- Parameters:
etag
- ETag value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addIfMatch
AddIf-Match
header with expected value. This header should work with ETag header sent by server response.- Parameters:
etag
- ETag value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addIfModifiedSince
AddIf-Modified-Since
value with expected date (date will be translated as GMT raw).- Parameters:
date
- Date.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addIfUnmodifiedSince
AddIf-Unmodified-Since
value with expected date (date will be translated as GMT raw).- Parameters:
date
- Date.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addXHttpMethodOverride
AddX-Http-Method-Override
value with HTTP verb to override. This method is generally used withPOST
request to overridePUT
orDELETE
requests.- Parameters:
method
- Http method to override.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addCsrfToken
Add CSRF Token to http header (X-Csrf-Token
header).- Parameters:
token
- Token value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
overridePut
HttpRequest overridePut()Add @{code X-Http-Method-Override} value withPUT
value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
overrideDelete
HttpRequest overrideDelete()AddX-Http-Method-Override
value withDELETE
value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
execute
HttpResponse execute()Execute request and return http response: execution is synchronous and will block until response is available.- Returns:
- Http response.
-
executeJson
HttpResponse executeJson()Execute request and return http response: execution is synchronous and will block until response is available.This method automatically add json header (i.e methods
asJson()
andacceptJson()
will be automatically be called before execution).- Returns:
- Http response.
- See Also:
-
executeXml
HttpResponse executeXml()Execute request and return http response: execution is synchronous and will block until response is available.This method automatically add xml header (i.e methods
asXml()
andacceptXml()
will be automatically called before execution).- Returns:
- Http response.
- See Also:
-