Interface HttpRequest
- All Known Implementing Classes:
AbstractHttpRequest
public interface HttpRequest
HTTP request.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionAddAccept-Encodingheader with"gzip, deflate"value.Add header to specify that accept type is"application/json".acceptLanguage(String lang) AddAccept-Languageheader.Add header to specify that accept type is"application/xml".addAcceptEncoding(String encoding) AddAccept-Encodingheader.Add cookie to http request.Add cookie to http request.addCsrfToken(String token) Add CSRF Token to http header (X-Csrf-Tokenheader).addHeader(HttpHeader header) Add header.Add header.addIfMatch(String etag) AddIf-Matchheader with expected value.addIfModifiedSince(Date date) AddIf-Modified-Sincevalue with expected date (date will be translated as GMT raw).addIfNoneMatch(String etag) AddIf-None-Matchheader with expected value.addIfUnmodifiedSince(Date date) AddIf-Unmodified-Sincevalue with expected date (date will be translated as GMT raw).AddOriginheader.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) AddRefererheader.addXHttpMethodOverride(String method) AddX-Http-Method-Overridevalue 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-Overridevalue withDELETEvalue.Add @{code X-Http-Method-Override} value withPUTvalue.setBody(HttpRequestBody body) Set request body.withUserAgent(String userAgent) AddUser-Agentheader 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- Ifnameorvalueisnull.IllegalArgumentException- ifnameis blank.- See Also:
-
addHeader
Add header.- Parameters:
header- The header.- Returns:
- Http request that can be used for chaining.
- Throws:
NullPointerException- Ifheaderisnull.
-
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 throwUnsupportedOperationExceptionexception.- Parameters:
body- Body request.- Returns:
- Http request that can be used for chaining.
- Throws:
UnsupportedOperationException- If request method does not allow body (i.eGET,HEADorDELETE).
-
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-Languageheader.- Parameters:
lang- Accepted languages.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addOrigin
AddOriginheader.- Parameters:
origin- Origin value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addReferer
AddRefererheader.- Parameters:
referer- Referer value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addAcceptEncoding
AddAccept-Encodingheader.- Parameters:
encoding- Encoding value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
acceptGzip
HttpRequest acceptGzip()AddAccept-Encodingheader with"gzip, deflate"value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
withUserAgent
AddUser-Agentheader 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- Ifnameorvaluearenull.IllegalArgumentException- Ifnameis empty or blank.- See Also:
-
addIfNoneMatch
AddIf-None-Matchheader with expected value. This header should work withETagheader sent by server response.- Parameters:
etag- ETag value.- Returns:
- Http request that can be used for chaining.
- See Also:
-
addIfMatch
AddIf-Matchheader 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-Sincevalue 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-Sincevalue 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-Overridevalue with HTTP verb to override. This method is generally used withPOSTrequest to overridePUTorDELETErequests.- 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-Tokenheader).- 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 withPUTvalue.- Returns:
- Http request that can be used for chaining.
- See Also:
-
overrideDelete
HttpRequest overrideDelete()AddX-Http-Method-Overridevalue withDELETEvalue.- 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:
-