Package io.github.parthappm.http.client
Class Client
java.lang.Object
io.github.parthappm.http.client.Client
- Direct Known Subclasses:
HttpClient
,HttpsClient
A client class to implement the HTTP client functionality.
The object of this class cannot be created directly, either create an object of HttpClient of HttpsClient class.
-
Method Summary
Modifier and TypeMethodDescriptionSetter method to add or modify a single header to the existing list of headers.addParameter
(String key, String value) Setter method to add or modify a single parameter to the existing list of parameters.void
close()
Closes the socket connection to the serverfollowRedirect
(boolean followRedirect) Setter method for flag to whether follow redirect HTTP response.keepConnectionOpen
(boolean keepConnectionOpen) Setter method for flag to keep the connection open for the socket.request()
This method has to be called to make the HTTP request to the server after setting the required parameterssetBody
(byte[] body) Setter method to set the request bodySetter method add or modify multiple headers to the existing list of parameters.Setter method to set the HTTP Method.setParameters
(Map<String, String> parameters) Setter method to add or modify multiple parameters to the existing list of parameters.Setter method to set the path to be used after the host in url.protected void
Setter method for socket object.suppressException
(boolean suppressException) Setter method for flag to suppress any kind of exception.
-
Method Details
-
setSocket
Setter method for socket object.- Parameters:
socket
- The socket that will be used for HTTP protocol
-
suppressException
Setter method for flag to suppress any kind of exception.- Parameters:
suppressException
- The flag to suppress exceptions- Returns:
- The reference of the current object for chaining
-
keepConnectionOpen
Setter method for flag to keep the connection open for the socket.- Parameters:
keepConnectionOpen
- The flag whether to keep the connection open or close the socket- Returns:
- The reference of the current object for chaining
-
followRedirect
Setter method for flag to whether follow redirect HTTP response.- Parameters:
followRedirect
- The flag whether to make the next request depending on HTTP response- Returns:
- The reference of the current object for chaining
-
setMethod
Setter method to set the HTTP Method.- Parameters:
method
- The HTTP method to be used- Returns:
- The reference of the current object for chaining
-
setPath
Setter method to set the path to be used after the host in url.- Parameters:
path
- The url path- Returns:
- The reference of the current object for chaining
-
addParameter
Setter method to add or modify a single parameter to the existing list of parameters. To delete a parameter, set the value to null.- Parameters:
key
- The parameter keyvalue
- The parameter value- Returns:
- The reference of the current object for chaining
-
setParameters
Setter method to add or modify multiple parameters to the existing list of parameters. To delete a parameter, set the value to null.- Parameters:
parameters
- The map of new or extra parameters that are to be added to the existing list of parameters- Returns:
- The reference of the current object for chaining
-
addHeader
Setter method to add or modify a single header to the existing list of headers. To delete a header, set the value to null.- Parameters:
key
- The header namevalue
- The header value- Returns:
- The reference of the current object for chaining
-
setHeader
Setter method add or modify multiple headers to the existing list of parameters. To delete a parameter, set the value to null.- Parameters:
headers
- The map of new or extra headers that are to be added to the existing list of headers- Returns:
- The reference of the current object for chaining
-
setBody
Setter method to set the request body- Parameters:
body
- Bytes array representing the request body- Returns:
- The reference of the current object for chaining
-
request
This method has to be called to make the HTTP request to the server after setting the required parameters- Returns:
- Response object that contains all the details of the HTTP response for this particular request
- Throws:
IOException
- If any IOException occurs in the socket connection
-
close
Closes the socket connection to the server- Throws:
IOException
- If any IOException occurs in the process of closing the connection
-