Class Endpoint


  • public class Endpoint
    extends Object
    Represents a URL endpoint with an optional proxy (HTTP, SOCKS, or direct if no proxy is specified). Abstracts HTTP request operations involving common formats such as JSON, XML, YAML, CSV, and plain text. Typically, the methods of the Endpoint class are called indirectly through higher level APIs.
    • Constructor Detail

      • Endpoint

        public Endpoint​(String urlBase)
        Parameters:
        urlBase - The base URL for the endpoint. Can have name=value arguments.
      • Endpoint

        public Endpoint​(String urlBase,
                        String proxyAddr,
                        int proxyPort)
        Makes an HTTP proxied endpoint.
        Parameters:
        urlBase - The base URL for the endpoint. Can have name=value arguments.
        proxyAddr - The address of the proxy server, such as "http://my.proxyserver.com".
        proxyPort - The port number of the proxy server, typically 8080.
      • Endpoint

        public Endpoint​(String urlBase,
                        String proxyAddr,
                        Proxy.Type proxyType)
        Makes an proxied endpoint on port 8080.
        Parameters:
        urlBase - The base URL for the endpoint. Can have name=value arguments.
        proxyAddr - The address of the proxy server, such as "http://my.proxyserver.com".
        proxyType - The proxy type: HTTP or SOCKS. Use Endpoint(String) if there is no proxy server.
      • Endpoint

        public Endpoint​(String urlBase,
                        String proxyAddr,
                        int proxyPort,
                        Proxy.Type proxyType)
        Makes a proxied endpoint at the specified urlBase.
        Parameters:
        urlBase - The base URL for the endpoint. Can have name=value arguments.
        proxyAddr - The address of the proxy server, such as "http://my.proxyserver.com".
        proxyPort - The port number of the proxy server, typically 8080.
        proxyType - The proxy type: HTTP or SOCKS. Use Endpoint(String) if there is no proxy server.
    • Method Detail

      • withUrlSuffix

        public Endpoint withUrlSuffix​(String urlSuffix)
        Creates a new Endpoint with a base URL consisting of this endpoint's base URL + urlSuffix.
        Parameters:
        urlSuffix - Use the suffix to make a new url consisting of this endpoint's base URL + urlSuffix.
        Returns:
        A new Endpoint with a base URL consisting of this endpoint's base URL + urlSuffix.
      • sendCsvRequest

        public Object sendCsvRequest​(String httpMethod,
                                     Object jsonValue,
                                     Map<String,​String> headers,
                                     int timeout)
        Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to the endpoint with a CSV response.
        Parameters:
        httpMethod - The HTTP method to use: "GET", "POST", "PUT", or "PATCH"
        jsonValue - A JSON value to send (primitive/boxed type, String, List of JSON values, or Bindings of String/JSON value)
        Returns:
        A JSON bindings value parsed from the CSV response.
      • sendJsonRequest

        public Object sendJsonRequest​(String httpMethod,
                                      Object jsonValue,
                                      Map<String,​String> headers,
                                      int timeout)
        Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to the endpoint with a JSON response.
        Parameters:
        httpMethod - The HTTP method to use: "GET", "POST", "PUT", or "PATCH"
        jsonValue - A JSON value to send (primitive/boxed type, String, List of JSON values, or Bindings of String/JSON value)
        Returns:
        A JSON value parsed from the JSON response.
      • sendPlainTextRequest

        public Object sendPlainTextRequest​(String httpMethod,
                                           Object jsonValue,
                                           Map<String,​String> headers,
                                           int timeout)
        Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to a URL with a plain text response.
        Parameters:
        httpMethod - The HTTP method to use: "GET", "POST", "PUT", or "PATCH"
        jsonValue - A JSON value to send (primitive/boxed type, String, List of JSON values, or Bindings of String/JSON value)
        Returns:
        The raw response body as plain text
      • sendXmlRequest

        public Object sendXmlRequest​(String httpMethod,
                                     Object jsonValue,
                                     Map<String,​String> headers,
                                     int timeout)
        Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to a URL with an XML response.
        Parameters:
        httpMethod - The HTTP method to use: "GET", "POST", "PUT", or "PATCH"
        jsonValue - A JSON value to send (primitive/boxed type, String, List of JSON values, or Bindings of String/JSON value)
        Returns:
        The raw response body as XML
      • sendYamlRequest

        public Object sendYamlRequest​(String httpMethod,
                                      Object jsonValue,
                                      Map<String,​String> headers,
                                      int timeout)
        Use HTTP GET, POST, PUT, or PATCH to send JSON bindings to a URL with a YAML response.
        Parameters:
        httpMethod - The HTTP method to use: "GET", "POST", "PUT", or "PATCH"
        jsonValue - A JSON value to send (primitive/boxed type, String, List of JSON values, or Bindings of String/JSON value)
        Returns:
        The raw response body as YAML