Package com.longport

Class HttpClient

    • Method Detail

      • fromEnv

        public static HttpClient fromEnv()
                                  throws OpenApiException
        Create a new `HttpClient` from the given environment variables

        It first gets the environment variables from the .env file in the current directory. # Variables - `LONGPORT_HTTP_URL` - HTTP endpoint url - `LONGPORT_APP_KEY` - App key - `LONGPORT_APP_SECRET` - App secret - `LONGPORT_ACCESS_TOKEN` - Access token

        Returns:
        Config object
        Throws:
        OpenApiException - If an error occurs
      • request

        public <T> CompletableFuture<T> request​(Class<T> respClass,
                                                String method,
                                                String path)
                                         throws RuntimeException
        Performs a HTTP request
        Type Parameters:
        T - Response class type
        Parameters:
        respClass - Response class object, it can be null
        method - HTTP method, e.g. get, post
        path - Request path
        Returns:
        A Future representing the result of the operation
        Throws:
        RuntimeException - If an error occurs
      • request

        public <T> CompletableFuture<T> request​(Class<T> respClass,
                                                String method,
                                                String path,
                                                Object requestBody)
                                         throws RuntimeException
        Performs a HTTP request with body
        Type Parameters:
        T - Response class type
        Parameters:
        respClass - Response class object, it can be null
        method - HTTP method, e.g. get, post
        path - Request path
        requestBody - Request body, it can be null
        Returns:
        A Future representing the result of the operation
        Throws:
        RuntimeException - If an error occurs
      • request

        public <T> CompletableFuture<T> request​(Class<T> respClass,
                                                String method,
                                                String path,
                                                Object requestBody,
                                                HashMap<String,​String> headers)
                                         throws RuntimeException
        Performs a HTTP request with headers
        Type Parameters:
        T - Response class type
        Parameters:
        respClass - Response class object, it can be null
        method - HTTP method, e.g. get, post
        path - Request path
        requestBody - Request body, it can be null
        headers - Request headers, it can be null
        Returns:
        A Future representing the result of the operation
        Throws:
        RuntimeException