Class HttpRequest
java.lang.Object
de.oliver.fancyanalytics.sdk.utils.HttpRequest
-
Constructor Summary
ConstructorsConstructorDescriptionHttpRequest(String url) Constructs a new HttpRequest with the provided URL, method, body, and headers. -
Method Summary
Modifier and TypeMethodDescriptiongetBody()getUrl()send()Sends an HTTP request based on preset configuration including URL, method, body, and headers.Sets the body of the request.withHeader(String key, String value) Adds a header to the request.withHeaders(Map<String, String> headers) Sets the headers of the request.withMethod(String method) Sets the method of the request.withTimeout(Duration timeout) Sets the timeout of the request.
-
Constructor Details
-
HttpRequest
Constructs a new HttpRequest with the provided URL, method, body, and headers.- Parameters:
url- The URL to which the request is directed.method- The HTTP method to use (e.g., GET, POST).body- The body of the request. This can be any object that needs to be sent in the request body.headers- A map representing the headers to be included in the request, where the key is the header name and the value is the header value.
-
HttpRequest
-
-
Method Details
-
send
Sends an HTTP request based on preset configuration including URL, method, body, and headers.- Returns:
- the HttpResponse containing the response as a string from the executed HTTP request.
- Throws:
URISyntaxException- if the URL is not properly formatted.IOException- if an I/O error occurs when sending or receiving.InterruptedException- if the operation is interrupted.
-
getUrl
-
getMethod
-
withMethod
Sets the method of the request.- Parameters:
method- The method to use.- Returns:
- The HttpRequest.
-
getBody
-
withBody
Sets the body of the request.- Parameters:
body- The body of the request.- Returns:
- The HttpRequest.
-
getHeaders
-
withHeaders
Sets the headers of the request.- Parameters:
headers- The headers of the request.- Returns:
- The HttpRequest.
-
withHeader
Adds a header to the request.- Parameters:
key- The key of the header.value- The value of the header.- Returns:
- The HttpRequest.
-
getTimeout
-
withTimeout
Sets the timeout of the request.- Parameters:
timeout- The timeout of the request.- Returns:
- The HttpRequest.
-