Class HttpGet
java.lang.Object
me.pauleff.common.handlers.http.HttpGet
Sends HTTP GET requests and returns successful response bodies.
Prefer the static one-shot body(String) for simple calls. Use of(HttpClient)
when injecting a custom client (for example in tests).
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringSends an HTTP GET request with the default client and returns the body on success.Sends an HTTP GET request to the given URL and returns the response body on success.static HttpGetof(HttpClient client) Returns a handle that uses the givenHttpClient.static HttpGetReturns a handle that uses the shared defaultHttpClient.
-
Method Details
-
ofDefault
Returns a handle that uses the shared defaultHttpClient.- Returns:
- the default HTTP GET client
-
of
Returns a handle that uses the givenHttpClient.- Parameters:
client- the HTTP client to send requests with- Returns:
- an HTTP GET handle
- Throws:
NullPointerException- ifclientisnull
-
body
Sends an HTTP GET request with the default client and returns the body on success.- Parameters:
url- the absolute URL to request- Returns:
- the response body if the status code is
200;nullotherwise - Throws:
IOException- if the request fails or is interrupted
-
getBody
Sends an HTTP GET request to the given URL and returns the response body on success.- Parameters:
url- the absolute URL to request- Returns:
- the response body if the status code is
200;nullotherwise - Throws:
NullPointerException- ifurlisnullIOException- if the request fails or is interrupted
-