Package com.gmt2001.httpclient
Class HttpClient
java.lang.Object
com.gmt2001.httpclient.HttpClient
Performs HTTP requests
- Author:
- gmt2001
-
Method Summary
Modifier and TypeMethodDescriptionstatic HttpHeadersCreates a new, emptyHttpHeadersstatic HttpHeaderscreateHeaders(boolean isMutatorWithBody, boolean isJson) Creates a newHttpHeaderswith some default headers filled instatic HttpHeaderscreateHeaders(HttpMethod method, boolean isJson) Creates a newHttpHeaderswith some default headers filled instatic StringcreateQuery(Map<String, String> query) Takes a Map of query params and converts it to a query stringstatic HttpClientResponseShortcut to perform aHttpMethod.DELETErequest with the default headersstatic HttpClientResponsedelete(URI url, HttpHeaders requestHeaders) Shortcut to perform aHttpMethod.DELETErequest with the specified headersstatic HttpClientResponseShortcut to perform aHttpMethod.GETrequest with the default headersstatic HttpClientResponseget(URI url, HttpHeaders requestHeaders) Shortcut to perform aHttpMethod.GETrequest with the specified headersstatic HttpClientResponseShortcut to perform aHttpMethod.HEADrequest with the default headersstatic HttpClientResponsehead(URI url, HttpHeaders requestHeaders) Shortcut to perform a HEAD with the specified headersstatic booleanisMutatorWithBody(HttpMethod method) Indicates if the provided method is a mutator that can provide a request bodystatic HttpClientResponsepatch(URI url, HttpHeaders requestHeaders, String requestBody) Shortcut to perform aHttpMethod.PATCHrequest with the specified headersstatic HttpClientResponseShortcut to URL-encode a map of patch data then submit it as aHttpMethod.PATCHrequest with the specified headersstatic HttpClientResponsepatch(URI url, HttpHeaders requestHeaders, JSONObject json) Shortcut to stringify aJSONObjectand submit it as aHttpMethod.PATCHrequest with the specified headersstatic HttpClientResponseShortcut to perform a form-urlencodedHttpMethod.PATCHrequest with the default headersstatic HttpClientResponseShortcut to URL-encode a map of put data then submit it as a form-urlencodedHttpMethod.PATCHrequest with the default headersstatic HttpClientResponsepatch(URI url, JSONObject json) Shortcut to stringify aJSONObjectand submit it as aHttpMethod.PATCHrequest with the default headersstatic HttpClientResponsepost(URI url, HttpHeaders requestHeaders, String requestBody) Shortcut to perform aHttpMethod.POSTrequest with the specified headersstatic HttpClientResponseShortcut to URL-encode a map of post data then submit it as aHttpMethod.POSTrequest with the specified headersstatic HttpClientResponsepost(URI url, HttpHeaders requestHeaders, JSONObject json) Shortcut to stringify aJSONObjectand submit it as aHttpMethod.POSTrequest with the specified headersstatic HttpClientResponseShortcut to perform a form-urlencodedHttpMethod.POSTrequest with the default headersstatic HttpClientResponseShortcut to URL-encode a map of post data then submit it as a form-urlencodedHttpMethod.POSTrequest with the default headersstatic HttpClientResponsepost(URI url, JSONObject json) Shortcut to stringify aJSONObjectand submit it as aHttpMethod.POSTrequest with the default headersstatic HttpClientResponseput(URI url, HttpHeaders requestHeaders, String requestBody) Shortcut to perform aHttpMethod.PUTrequest with the specified headersstatic HttpClientResponseShortcut to URL-encode a map of put data then submit it as aHttpMethod.PUTrequest with the specified headersstatic HttpClientResponseput(URI url, HttpHeaders requestHeaders, JSONObject json) Shortcut to stringify aJSONObjectand submit it as aHttpMethod.PUTrequest with the specified headersstatic HttpClientResponseShortcut to perform a form-urlencodedHttpMethod.PUTrequest with the default headersstatic HttpClientResponseShortcut to URL-encode a map of put data then submit it as a form-urlencodedHttpMethod.PUTrequest with the default headersstatic HttpClientResponseput(URI url, JSONObject json) Shortcut to stringify aJSONObjectand submit it as aHttpMethod.PUTrequest with the default headersstatic HttpClientResponserequest(HttpMethod method, URI url, HttpHeaders requestHeaders, String requestBody) Performs an HTTP requeststatic StringurlencodePost(Map<String, String> postData) Converts a map of post data into a URL-encoded string suitable for the content type application/x-www-form-urlencoded
-
Method Details
-
request
public static HttpClientResponse request(HttpMethod method, URI url, HttpHeaders requestHeaders, String requestBody) Performs an HTTP request- Parameters:
method- the HTTP methodurl- the URL to requestrequestHeaders- the request headers to sendrequestBody- the request body to send if method isHttpMethod.POST,HttpMethod.PUT, orHttpMethod.PATCH;nullfor other methods- Returns:
- a
HttpClientResponsewith the results
-
head
Shortcut to perform aHttpMethod.HEADrequest with the default headers- Parameters:
url- the URL to request- Returns:
- a
HttpClientResponsewith the results
-
head
Shortcut to perform a HEAD with the specified headers- Parameters:
url- the URL to requestrequestHeaders- the headers to send- Returns:
- a
HttpClientResponsewith the results
-
get
Shortcut to perform aHttpMethod.GETrequest with the default headers- Parameters:
url- the URL to request- Returns:
- a
HttpClientResponsewith the results
-
get
Shortcut to perform aHttpMethod.GETrequest with the specified headers- Parameters:
url- the URL to requestrequestHeaders- the headers to send- Returns:
- a
HttpClientResponsewith the results
-
post
Shortcut to perform a form-urlencodedHttpMethod.POSTrequest with the default headers- Parameters:
url- the URL to requestrequestBody- the request body- Returns:
- a
HttpClientResponsewith the results
-
post
Shortcut to perform aHttpMethod.POSTrequest with the specified headers- Parameters:
url- the URL to requestrequestHeaders- the headers to sendrequestBody- the request body- Returns:
- a
HttpClientResponsewith the results
-
post
Shortcut to URL-encode a map of post data then submit it as a form-urlencodedHttpMethod.POSTrequest with the default headers- Parameters:
url- the URL to requestpostData- a map of post data- Returns:
- a
HttpClientResponsewith the results
-
post
public static HttpClientResponse post(URI url, HttpHeaders requestHeaders, Map<String, String> postData) Shortcut to URL-encode a map of post data then submit it as aHttpMethod.POSTrequest with the specified headers- Parameters:
url- the URL to requestrequestHeaders- the headers to sendpostData- a map of post data- Returns:
- a
HttpClientResponsewith the results
-
post
Shortcut to stringify aJSONObjectand submit it as aHttpMethod.POSTrequest with the default headers- Parameters:
url- the URL to sendjson- the JSON object to send- Returns:
- a
HttpClientResponsewith the results
-
post
Shortcut to stringify aJSONObjectand submit it as aHttpMethod.POSTrequest with the specified headers- Parameters:
url- the URL to sendrequestHeaders- the headers to sendjson- the JSON object to send- Returns:
- a
HttpClientResponsewith the results
-
put
Shortcut to perform a form-urlencodedHttpMethod.PUTrequest with the default headers- Parameters:
url- the URL to sendrequestBody- the request body- Returns:
- a
HttpClientResponsewith the results
-
put
Shortcut to perform aHttpMethod.PUTrequest with the specified headers- Parameters:
url- the URL to requestrequestHeaders- the headers to sendrequestBody- the request body- Returns:
- a
HttpClientResponsewith the results
-
put
Shortcut to URL-encode a map of put data then submit it as a form-urlencodedHttpMethod.PUTrequest with the default headers- Parameters:
url- the URL to requestputData- a map of put data- Returns:
- a
HttpClientResponsewith the results
-
put
public static HttpClientResponse put(URI url, HttpHeaders requestHeaders, Map<String, String> putData) Shortcut to URL-encode a map of put data then submit it as aHttpMethod.PUTrequest with the specified headers- Parameters:
url- the URL to requestrequestHeaders- the headers to sendputData- a map of put data- Returns:
- a
HttpClientResponsewith the results
-
put
Shortcut to stringify aJSONObjectand submit it as aHttpMethod.PUTrequest with the default headers- Parameters:
url- the URL to sendjson- the JSON object to send- Returns:
- a
HttpClientResponsewith the results
-
put
Shortcut to stringify aJSONObjectand submit it as aHttpMethod.PUTrequest with the specified headers- Parameters:
url- the URL to sendrequestHeaders- the headers to sendjson- the JSON object to send- Returns:
- a
HttpClientResponsewith the results
-
patch
Shortcut to perform a form-urlencodedHttpMethod.PATCHrequest with the default headers- Parameters:
url- the URL to sendrequestBody- the request body- Returns:
- a
HttpClientResponsewith the results
-
patch
Shortcut to perform aHttpMethod.PATCHrequest with the specified headers- Parameters:
url- the URL to requestrequestHeaders- the headers to sendrequestBody- the request body- Returns:
- a
HttpClientResponsewith the results
-
patch
Shortcut to URL-encode a map of put data then submit it as a form-urlencodedHttpMethod.PATCHrequest with the default headers- Parameters:
url- the URL to requestpatchData- a map of patch data- Returns:
- a
HttpClientResponsewith the results
-
patch
public static HttpClientResponse patch(URI url, HttpHeaders requestHeaders, Map<String, String> patchData) Shortcut to URL-encode a map of patch data then submit it as aHttpMethod.PATCHrequest with the specified headers- Parameters:
url- the URL to requestrequestHeaders- the headers to sendpatchData- a map of patch data- Returns:
- a
HttpClientResponsewith the results
-
patch
Shortcut to stringify aJSONObjectand submit it as aHttpMethod.PATCHrequest with the default headers- Parameters:
url- the URL to sendjson- the JSON object to send- Returns:
- a
HttpClientResponsewith the results
-
patch
Shortcut to stringify aJSONObjectand submit it as aHttpMethod.PATCHrequest with the specified headers- Parameters:
url- the URL to sendrequestHeaders- the headers to sendjson- the JSON object to send- Returns:
- a
HttpClientResponsewith the results
-
delete
Shortcut to perform aHttpMethod.DELETErequest with the default headers- Parameters:
url- the URL to request- Returns:
- a
HttpClientResponsewith the results
-
delete
Shortcut to perform aHttpMethod.DELETErequest with the specified headers- Parameters:
url- the URL to requestrequestHeaders- the headers to send- Returns:
- a
HttpClientResponsewith the results
-
urlencodePost
Converts a map of post data into a URL-encoded string suitable for the content type application/x-www-form-urlencodedTo put only a name without the
=value, set the value tonull- Parameters:
postData- a map of post data- Returns:
- a URL encoded string
-
createHeaders
Creates a new, emptyHttpHeaders- Returns:
- an empty
HttpHeaders
-
createHeaders
Creates a newHttpHeaderswith some default headers filled in- Parameters:
method- the method that is going to be requested. If it is a mutator method that can provide a body, the content type may be setisJson- iftrue, sets the accept toapplication/json- Returns:
- a
HttpHeaderswith some default headers, if the parameters require them
-
createHeaders
Creates a newHttpHeaderswith some default headers filled in- Parameters:
isMutatorWithBody- iftrue, sets the content type. If isJson isfalse, sets toapplication/x-www-form-urlencodedisJson- iftrue, sets the accept toapplication/json. If isMutator istrue, sets the content type as well- Returns:
- a
HttpHeaderswith some default headers, if the parameters require them
-
isMutatorWithBody
Indicates if the provided method is a mutator that can provide a request body- Parameters:
method- the method to test- Returns:
trueif theHttpMethodspecified is a mutator type
-
createQuery
Takes a Map of query params and converts it to a query stringTo put only a name without the
=value, set the value tonull- Parameters:
query- the query params- Returns:
- a URL encoded string, including the
?prefix
-