public class Client extends Object implements Closeable
| Constructor and Description |
|---|
Client()
Constructor for using the default CloseableHttpClient.
|
Client(Boolean test)
Constructor for passing in a test parameter to allow for http calls.
|
Client(org.apache.http.impl.client.CloseableHttpClient httpClient)
Constructor for passing in an httpClient, typically for mocking.
|
Client(org.apache.http.impl.client.CloseableHttpClient httpClient,
Boolean test)
Constructor for passing in an httpClient and test parameter to allow for http calls.
|
| Modifier and Type | Method and Description |
|---|---|
Response |
api(Request request)
A thin wrapper around the HTTP methods.
|
URI |
buildUri(String baseUri,
String endpoint,
Map<String,String> queryParams)
Add query parameters to a URL.
|
void |
close()
Closes the http client.
|
Response |
delete(Request request)
Make a DELETE request and provide the status code and response headers.
|
void |
finalize()
Closes and finalizes the http client.
|
Response |
get(Request request)
Make a GET request and provide the status code, response body and
response headers.
|
Response |
getResponse(org.apache.http.client.methods.CloseableHttpResponse response)
Prepare a Response object from an API call via Apache's HTTP client.
|
Response |
patch(Request request)
Make a PATCH request and provide the status code, response body and
response headers.
|
Response |
post(Request request)
Make a POST request and provide the status code, response body and
response headers.
|
Response |
put(Request request)
Make a PUT request and provide the status code, response body and
response headers.
|
public Client()
public Client(org.apache.http.impl.client.CloseableHttpClient httpClient)
httpClient - an Apache CloseableHttpClientpublic Client(Boolean test)
test - is a Boolpublic Client(org.apache.http.impl.client.CloseableHttpClient httpClient,
Boolean test)
httpClient - an Apache CloseableHttpClienttest - is a Boolpublic URI buildUri(String baseUri, String endpoint, Map<String,String> queryParams) throws URISyntaxException
baseUri - (e.g. "api.sendgrid.com")endpoint - (e.g. "/your/endpoint/path")queryParams - map of key, values representing the query parametersURISyntaxException - in of a URI syntax errorpublic Response getResponse(org.apache.http.client.methods.CloseableHttpResponse response) throws IOException
response - from a call to a CloseableHttpClientIOException - in case of a network errorpublic Response get(Request request) throws URISyntaxException, IOException
request - the request objectURISyntaxException - in case of a URI syntax errorIOException - in case of a network errorpublic Response post(Request request) throws URISyntaxException, IOException
request - the request objectURISyntaxException - in case of a URI syntax errorIOException - in case of a network errorpublic Response patch(Request request) throws URISyntaxException, IOException
request - the request objectURISyntaxException - in case of a URI syntax errorIOException - in case of a network errorpublic Response put(Request request) throws URISyntaxException, IOException
request - the request objectURISyntaxException - in case of a URI syntax errorIOException - in case of a network errorpublic Response delete(Request request) throws URISyntaxException, IOException
request - the request objectURISyntaxException - in case of a URI syntax errorIOException - in case of a network errorpublic Response api(Request request) throws IOException
request - the request objectIOException - in case of a network errorpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOException - in case of a network errorCopyright © 2022. All rights reserved.