Package com.sparkpost.transport
Class RestConnection
java.lang.Object
com.sparkpost.transport.RestConnection
- All Implemented Interfaces:
IRestConnection
public class RestConnection extends Object implements IRestConnection
The REST connection class wraps HTTP requests to the SparkPost API.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRestConnection.MethodSupported HTTP methods -
Field Summary
Fields inherited from interface com.sparkpost.transport.IRestConnection
defaultApiEndpoint, SPC_EU_ENDPOINT, SPC_US_ENDPOINT, SUBACCOUNT_HEADER -
Constructor Summary
Constructors Constructor Description RestConnection(Client client)Create a REST connection object.RestConnection(Client client, String baseUrl)Create a REST connection object. -
Method Summary
Modifier and Type Method Description voidaddHeader(String key, String value)Responsedelete(Endpoint endpoint)Perform an HTTP DELETE request.Responseget(Endpoint endpoint)Perform an HTTP GET request.Responsepost(Endpoint endpoint, String json)Perform an HTTP POST request.Responseput(Endpoint endpoint, String json)Perform an HTTP PUT request.
-
Constructor Details
-
RestConnection
Create a REST connection object. The default endpoint defaultApiEndpoint will be used for connections.- Parameters:
client- Client object to use (in particular for authentication info)- Throws:
SparkPostException- if something goes wrong
-
RestConnection
Create a REST connection object. The given baseUrl will be used for connections- Parameters:
client- Client object to use (in particular for authentication info)baseUrl- Endpoint to use instead of the default defaultApiEndpoint- Throws:
SparkPostException- if something goes wrong
-
-
Method Details
-
get
Description copied from interface:IRestConnectionPerform an HTTP GET request. This method throws an exception if the server returns anything else than a 200.- Specified by:
getin interfaceIRestConnection- Parameters:
endpoint- API endpoint to send the request to.- Returns:
- Server response to the request.
- Throws:
SparkPostException- if something goes wrong
-
post
Description copied from interface:IRestConnectionPerform an HTTP POST request. This method throws an exception if the server returns anything else than a 200.- Specified by:
postin interfaceIRestConnection- Parameters:
endpoint- API endpoint to send the request to.json- POST data block to send with the request. May be null.- Returns:
- Server response to the request
- Throws:
SparkPostException- if something goes wrong
-
put
Description copied from interface:IRestConnectionPerform an HTTP PUT request. This method throws an exception if the server returns anything else than a 200.- Specified by:
putin interfaceIRestConnection- Parameters:
endpoint- API endpoint to send the request to.json- PUT data block to send with the request. May be null.- Returns:
- Server response to the request.
- Throws:
SparkPostException- if something goes wrong
-
delete
Description copied from interface:IRestConnectionPerform an HTTP DELETE request. This method throws an exception if the server returns anything else than a 200.- Specified by:
deletein interfaceIRestConnection- Parameters:
endpoint- API endpoint to send the request to.- Returns:
- Server response to the request.
- Throws:
SparkPostException- if something goes wrong
-
addHeader
- Specified by:
addHeaderin interfaceIRestConnection- Parameters:
key- The HTTP header keyvalue- The HTTP header value
-