Package org.openhab.core.io.net.http
Class HttpRequestBuilder
java.lang.Object
org.openhab.core.io.net.http.HttpRequestBuilder
Builder class to construct http requests
- Author:
- Martin van Wingerden - Initial contribution
-
Method Summary
Modifier and TypeMethodDescriptionExecutes the build requeststatic HttpRequestBuilder
Construct an http request builder to get data from anurl
static HttpRequestBuilder
Construct an http request builder to post data to aurl
withContent
(String content) Add content to this requestwithContent
(String content, String contentType) Add content with a specific type to this requestwithHeader
(String header, String value) Add an additional header to the requestwithTimeout
(Duration timeout) Add a timeout for this request
-
Method Details
-
getFrom
Construct an http request builder to get data from anurl
- Parameters:
url
- to fetch the data from- Returns:
- a request builder to construct and complete the request
-
postTo
Construct an http request builder to post data to aurl
- Parameters:
url
- to post data to- Returns:
- a request builder to construct and complete the request
-
withTimeout
Add a timeout for this request- Parameters:
timeout
- the timeout for this http request as aDuration
- Returns:
- a request builder to construct and complete the request
-
withHeader
Add an additional header to the request- Parameters:
header
- name of the header, eg. Content-Typevalue
- value of the header, eg. "application/json"- Returns:
- a request builder to construct and complete the request
-
withContent
Add content to this request- Parameters:
content
- a string containing the data to be pushed to theurl
- Returns:
- a request builder to construct and complete the request
-
withContent
Add content with a specific type to this request- Parameters:
content
- a string containing the data to be pushed to theurl
contentType
- the content type of the givencontent
- Returns:
- a request builder to construct and complete the request
-
getContentAsString
Executes the build request- Returns:
- the response body or
null
when the request went wrong - Throws:
IOException
- when the request execution failed, timed out or it was interrupted
-