HttpClient/CurlClient
DotHRB provides specialized classes for accessing external services as a client.
| Class | Purpose | Key Feature |
|---|---|---|
| HttpClient | Accessing local services. | Designed to be lean and fast for HTTP only connections. |
| CurlClient | Calling external services. | Prioritizes compatibility and robustness over raw performance by using the system installed curl command. |
Both clients share a unified interface, allowing them to be easily swapped out when needed.
function main()
local oClient := HttpClient():new() // or CurlClient():new()
local aPromises
local hPromise1 := oClient:getAsync("https://jsonplaceholder.typicode.com/posts/1")
local hPromise2 := oClient:getAsync("https://jsonplaceholder.typicode.com/posts/2")
local hPromise3 := oClient:getAsync("https://jsonplaceholder.typicode.com/posts/3")
aPromises := promiseAll({hPromise3, hPromise1, hPromise2})
aeval(aPromises, {|oResponse|
if !oResponse:isSuccessSuccessStatusCode()
outstd(oResponse:getErrorCode(), hb_eol())
outstd(oResponse:getError(), hb_eol())
else
outstd(oResponse:nStatusCode, hb_eol())
outstd(oResponse:cReasonPhrase, hb_eol())
outstd(oResponse:getHeader("date"), hb_eol())
outstd(oResponse:getHeader("content-type"), hb_eol())
outstd(oResponse:cResponseBody, hb_eol())
endif
return nil
})
return nil