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.
  • Constructor Details

    • RestConnection

      public RestConnection​(Client client) throws SparkPostException
      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

      public RestConnection​(Client client, String baseUrl) throws SparkPostException
      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

      public Response get​(Endpoint endpoint) throws SparkPostException
      Description copied from interface: IRestConnection
      Perform an HTTP GET request. This method throws an exception if the server returns anything else than a 200.
      Specified by:
      get in interface IRestConnection
      Parameters:
      endpoint - API endpoint to send the request to.
      Returns:
      Server response to the request.
      Throws:
      SparkPostException - if something goes wrong
    • post

      public Response post​(Endpoint endpoint, String json) throws SparkPostException
      Description copied from interface: IRestConnection
      Perform an HTTP POST request. This method throws an exception if the server returns anything else than a 200.
      Specified by:
      post in interface IRestConnection
      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

      public Response put​(Endpoint endpoint, String json) throws SparkPostException
      Description copied from interface: IRestConnection
      Perform an HTTP PUT request. This method throws an exception if the server returns anything else than a 200.
      Specified by:
      put in interface IRestConnection
      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

      public Response delete​(Endpoint endpoint) throws SparkPostException
      Description copied from interface: IRestConnection
      Perform an HTTP DELETE request. This method throws an exception if the server returns anything else than a 200.
      Specified by:
      delete in interface IRestConnection
      Parameters:
      endpoint - API endpoint to send the request to.
      Returns:
      Server response to the request.
      Throws:
      SparkPostException - if something goes wrong
    • addHeader

      public void addHeader​(String key, String value)
      Specified by:
      addHeader in interface IRestConnection
      Parameters:
      key - The HTTP header key
      value - The HTTP header value