- java.lang.Object
-
- com.github.alexdlaird.http.DefaultHttpClient
-
- All Implemented Interfaces:
HttpClient
public class DefaultHttpClient extends java.lang.Object implements HttpClient
A default client for executing JSON-based HTTP requests.Basic Usage
final HttpClient httpClient = new DefaultHttpClient.Builder(); final SomePOJORequest postPojo = new MyPOJO("id", "data"); final Response<SomePOJOResponse> postResponse = httpClient.post("http://localhost/pojo", postPojo, SomePOJOResponse.class); final Response<SomePOJOResponse> getResponse = httpClient.get("http://localhost/pojo/id", SomePOJOResponse.class); final SomePOJORequest putPojo = new MyPOJO("updated-data"); final Response<SomePOJOResponse> postResponse = httpClient.post("http://localhost/pojo/id", putPojo, SomePOJOResponse.class); final Response<Map> deleteResponse = httpClient.delete("http://localhost/pojo/id");
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DefaultHttpClient.Builder
Builder for aDefaultHttpClient
, see docs for that class for example usage.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.net.HttpURLConnection
createHttpUrlConnection(java.lang.String url)
Override this method if you could like to implement a custom URL connection.<B> Response<B>
delete(java.lang.String url, java.util.List<Parameter> parameters, java.util.Map<java.lang.String,java.lang.String> additionalHeaders, java.lang.Class<B> clazz)
Perform DELETE operation against an endpoint.<B> Response<B>
get(java.lang.String url, java.util.List<Parameter> parameters, java.util.Map<java.lang.String,java.lang.String> additionalHeaders, java.lang.Class<B> clazz)
Perform GET operation against an endpoint.<R,B>
Response<B>post(java.lang.String url, R request, java.util.List<Parameter> parameters, java.util.Map<java.lang.String,java.lang.String> additionalHeaders, java.lang.Class<B> clazz)
Perform POST operation against an endpoint.<R,B>
Response<B>put(java.lang.String url, R request, java.util.List<Parameter> parameters, java.util.Map<java.lang.String,java.lang.String> additionalHeaders, java.lang.Class<B> clazz)
Perform PUT operation against an endpoint.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.github.alexdlaird.http.HttpClient
delete, delete, get, modifyConnection, post, put
-
-
-
-
Method Detail
-
get
public <B> Response<B> get(java.lang.String url, java.util.List<Parameter> parameters, java.util.Map<java.lang.String,java.lang.String> additionalHeaders, java.lang.Class<B> clazz)
Description copied from interface:HttpClient
Perform GET operation against an endpoint.- Specified by:
get
in interfaceHttpClient
- Type Parameters:
B
- The response body type.- Parameters:
url
- The URL on which to perform the operation.parameters
- An arbitrary number of parameters to add to the URL.additionalHeaders
- Additional headers for the request.clazz
- The class for the Response's body.- Returns:
- The results of the query.
-
post
public <R,B> Response<B> post(java.lang.String url, R request, java.util.List<Parameter> parameters, java.util.Map<java.lang.String,java.lang.String> additionalHeaders, java.lang.Class<B> clazz)
Description copied from interface:HttpClient
Perform POST operation against an endpoint.- Specified by:
post
in interfaceHttpClient
- Type Parameters:
R
- The Request type.B
- The Response body type.- Parameters:
url
- The URL on which to perform the operation.request
- The element to be serialized into the request body.parameters
- An arbitrary number of parameters to add to the URL.additionalHeaders
- Additional headers for the request.clazz
- The class for the Response's body.- Returns:
- The results of the query.
-
put
public <R,B> Response<B> put(java.lang.String url, R request, java.util.List<Parameter> parameters, java.util.Map<java.lang.String,java.lang.String> additionalHeaders, java.lang.Class<B> clazz)
Description copied from interface:HttpClient
Perform PUT operation against an endpoint.- Specified by:
put
in interfaceHttpClient
- Type Parameters:
R
- The Request type.B
- The Response body type.- Parameters:
url
- The URL on which to perform the operation.request
- The element to be serialized into the request body.parameters
- An arbitrary number of parameters to add to the URL.additionalHeaders
- Additional headers for the request.clazz
- The class for the Response's body.- Returns:
- The results of the query.
-
delete
public <B> Response<B> delete(java.lang.String url, java.util.List<Parameter> parameters, java.util.Map<java.lang.String,java.lang.String> additionalHeaders, java.lang.Class<B> clazz)
Description copied from interface:HttpClient
Perform DELETE operation against an endpoint.- Specified by:
delete
in interfaceHttpClient
- Type Parameters:
B
- The Response body type.- Parameters:
url
- The URL on which to perform the operation.parameters
- An arbitrary number of parameters to add to the URL.additionalHeaders
- Additional headers for the request.clazz
- The class for the Response's body.- Returns:
- The results of the query.
-
createHttpUrlConnection
protected java.net.HttpURLConnection createHttpUrlConnection(java.lang.String url) throws java.io.IOException
Override this method if you could like to implement a custom URL connection.- Parameters:
url
- The URL to connect to.- Returns:
- A URL connection.
- Throws:
java.io.IOException
- An I/O exception has occurred.
-
-