HttpAsyncClient
Overview
Module
- package:
@aerokit/sdk/http - source: http/client-async.ts
- last updated:
The HttpAsyncClient class provides a JavaScript/TypeScript wrapper (Facade) for making asynchronous HTTP requests using the underlying Java HTTP client. It allows developers to perform non-blocking HTTP operations by defining success, error, and cancel callbacks as strings of executable JavaScript code. The class supports all standard HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, TRACE) and accepts a comprehensive set of request options that mirror the capabilities of the Java client.
Key Features:
- Asynchronous Execution: All HTTP methods return immediately, with callbacks executed upon completion.
- Comprehensive Request Options: Supports a wide range of configuration options for fine-tuning HTTP requests.
- Callback Flexibility: Callbacks are defined as strings of JavaScript code, allowing for dynamic execution in the JVM environment.
Use Cases:
- Non-blocking API Calls: Ideal for scenarios where you want to perform HTTP requests without blocking the main execution thread.
- Complex Request Configurations: Suitable for advanced use cases that require detailed request configurations and handling.
Example Usage:
import { HttpAsyncClient } from "@aerokit/sdk/http";
const client = HttpAsyncClient.getInstance();
client.getAsync("https://api.example.com/data", {
success: "function(response) { console.log('Success:', response); }",
error: "function(error) { console.error('Error:', error); }"
}, {
headers: [{ name: 'Authorization', value: 'Bearer token' }],
params: [{ name: 'query', value: 'search term' }]
});Classes
HttpAsyncClient
getAsync()
Executes an asynchronous HTTP GET request.
tsgetAsync(url: string, config: HttpClientAsyncConfig, options: HttpClientRequestOptions): void;
Parameter Type Description urlstringThe target URL. configHttpClientAsyncConfigThe callback configuration object. optionsHttpClientRequestOptionsRequest configuration options (e.g., headers, body, params). Returns
- Type:
void- Description:
postAsync()
Executes an asynchronous HTTP POST request.
tspostAsync(url: string, config: HttpClientAsyncConfig, options: HttpClientRequestOptions): void;
Parameter Type Description urlstringThe target URL. configHttpClientAsyncConfigThe callback configuration object. optionsHttpClientRequestOptionsRequest configuration options. Returns
- Type:
void- Description:
putAsync()
Executes an asynchronous HTTP PUT request.
tsputAsync(url: string, config: HttpClientAsyncConfig, options: HttpClientRequestOptions): void;
Parameter Type Description urlstringThe target URL. configHttpClientAsyncConfigThe callback configuration object. optionsHttpClientRequestOptionsRequest configuration options. Returns
- Type:
void- Description:
patchAsync()
Executes an asynchronous HTTP PATCH request.
tspatchAsync(url: string, config: HttpClientAsyncConfig, options: HttpClientRequestOptions): void;
Parameter Type Description urlstringThe target URL. configHttpClientAsyncConfigThe callback configuration object. optionsHttpClientRequestOptionsRequest configuration options. Returns
- Type:
void- Description:
deleteAsync()
Executes an asynchronous HTTP DELETE request.
tsdeleteAsync(url: string, config: HttpClientAsyncConfig, options: HttpClientRequestOptions): void;
Parameter Type Description urlstringThe target URL. configHttpClientAsyncConfigThe callback configuration object. optionsHttpClientRequestOptionsRequest configuration options. Returns
- Type:
void- Description:
headAsync()
Executes an asynchronous HTTP HEAD request.
tsheadAsync(url: string, config: HttpClientAsyncConfig, options: HttpClientRequestOptions): void;
Parameter Type Description urlstringThe target URL. configHttpClientAsyncConfigThe callback configuration object. optionsHttpClientRequestOptionsRequest configuration options. Returns
- Type:
void- Description:
traceAsync()
Executes an asynchronous HTTP TRACE request.
tstraceAsync(url: string, config: HttpClientAsyncConfig, options: HttpClientRequestOptions): void;
Parameter Type Description urlstringThe target URL. configHttpClientAsyncConfigThe callback configuration object. optionsHttpClientRequestOptionsRequest configuration options. Returns
- Type:
void- Description:
execute()
Initiates the execution of queued asynchronous requests (depending on the underlying Java client's threading model).
tsexecute(): void;Returns
- Type:
void- Description:
