Class HttpClient

    • Method Detail

      • fromApikey

        public static HttpClient fromApikey​(String appKey,
                                            String appSecret,
                                            String accessToken)
        Create a new HttpClient using API Key authentication.

        LONGBRIDGE_HTTP_URL is read from the environment automatically.

        Parameters:
        appKey - App key
        appSecret - App secret
        accessToken - Access token
        Returns:
        HttpClient object
      • fromApikey

        public static HttpClient fromApikey​(String appKey,
                                            String appSecret,
                                            String accessToken,
                                            String httpUrl)
        Create a new HttpClient using API Key authentication with a custom HTTP endpoint URL.

        The httpUrl parameter overrides LONGBRIDGE_HTTP_URL from the environment.

        Parameters:
        appKey - App key
        appSecret - App secret
        accessToken - Access token
        httpUrl - HTTP endpoint URL override
        Returns:
        HttpClient object
      • fromApikeyEnv

        public static HttpClient fromApikeyEnv()
                                        throws OpenApiException
        Create a new HttpClient from environment variables (API Key authentication).

        Variables: LONGBRIDGE_HTTP_URL, LONGBRIDGE_APP_KEY, LONGBRIDGE_APP_SECRET, LONGBRIDGE_ACCESS_TOKEN

        Returns:
        HttpClient 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 - If the request fails