Integration
HttpClient and binding-specific network APIs provide host data access. Define timeouts, cancellation, errors and response-size limits and keep waits off the UI thread. Validate returned data before using it as interface text or application state.
Constraints and troubleshooting
Resource paths depend on application deployment and actual loading rules. Finding an image or font on a development machine does not establish package completeness. Verify pages, CSS, fonts, images and extension resources from a clean directory. Do not concatenate network data into Lua code.
Choose the callback thread
HttpClient::fetchSync blocks the calling thread. fetchAsync may complete on a worker thread. Use fetchAsyncOnMainThread to update UI in the callback, after platform initialization and while the event loop runs.
void fetchForUi(kui::HttpClient& client, const kui::String& url,
kui::HttpClient::Callback onComplete) {
client.fetchAsyncOnMainThread(url, std::move(onComplete), 10.0);
}Responses and cancellation
Response contains statusCode, body, contentType and error. Check transport errors and HTTP status, apply application-level size limits and then parse content. Keep HttpClient owned by the application. Cancel unneeded requests and prevent callbacks from accessing elements from destroyed documents.
client.cancelAll();Put network results into the UI
Verify a minimal scenario in this order before integrating the full application.
- Show loading after a click and control duplicate requests.
- Use async APIs and distinguish request failures, HTTP status and parsing errors.
- Set a timeout, avoid old nodes after closing a page, and keep credentials in the host.
- Provide visible success, failure, empty and retry states instead of console output only.
Something unclear?
Report an issue on this page →