HttpClient
HTTP client
html := HttpClient->QuickGet(Url->New("http://worldtimeapi.org/api/ip"))->ToString();
if(html <> Nil) {
html->PrintLine();
};Operations
- New
- AddHeader
- Delete
- EnableCookies
- Get
- GetCookie
- GetCookies
- GetRequestHeaders
- GetResponseHeaders
- HasCookie
- Patch
- Post
- Put
- QuickDelete
- QuickGet
- QuickPatch
- QuickPost
- QuickPut
- RemoveHeader
- SetCookie
- SetMaxRedirects
- SetRetry
AddHeader #
Adds a HTTP request header
method : public : AddHeader(name:String, value:String) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| name | String | header name |
| value | String | header value |
Example
client := Web.HTTP.HttpClient->New();
client->AddHeader("Authorization", "Bearer my-token-123");
client->AddHeader("Accept", "application/json");
response := client->Get(Web.HTTP.Url->New("https://api.example.com/data"));
if(response <> Nil) {
response->ToString()->PrintLine();
};Delete #
Performs a HTTP DELETE
method : public : Delete(url:Web.HTTP.Url) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
Return
| Type | Description |
|---|---|
| Response | string read |
Example
client := Web.HTTP.HttpClient->New();
response := client->Delete(Web.HTTP.Url->New("https://api.example.com/items/42"));
response->GetStatusCode()->PrintLine(); # 204Delete #
Performs a HTTP DELETE
method : public : Delete(url:Web.HTTP.Url, content_type:String) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| content_type | String | content type |
Return
| Type | Description |
|---|---|
| Response | string read |
Delete #
Performs a HTTP DELETE
method : public : Delete(url:Web.HTTP.Url, data:Byte[]) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
Return
| Type | Description |
|---|---|
| Response | string read |
Delete #
Performs a HTTP DELETE
method : public : Delete(url:Web.HTTP.Url, data:Byte[], content_type:String) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
| content_type | String | content type |
Return
| Type | Description |
|---|---|
| Response | string read |
EnableCookies #
Sets cookie support
method : public : EnableCookies(cookies_enabled:Bool) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| cookies_enabled | Bool | true if cookies are enabled, false otherwise |
Example
client := Web.HTTP.HttpClient->New(false);
client->EnableCookies(true);Get #
Performs a HTTP GET
method : public : Get(url:Web.HTTP.Url) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
Return
| Type | Description |
|---|---|
| Response | string read |
Example
client := Web.HTTP.HttpClient->New();
response := client->Get(Web.HTTP.Url->New("https://httpbin.org/get"));
if(response <> Nil & response->GetStatusCode() = 200) {
response->ToString()->PrintLine();
};Get #
Performs a HTTP GET
method : public : Get(url:Web.HTTP.Url, content_type:String) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| content_type | String | content type |
Return
| Type | Description |
|---|---|
| Response | string read |
Example
client := Web.HTTP.HttpClient->New();
response := client->Get(Web.HTTP.Url->New("https://api.example.com/data"), "application/json");
if(response <> Nil) {
response->ToString()->PrintLine();
};GetCookie #
Get a cookie
method : public : GetCookie(name:String) ~ CookieParameters
| Name | Type | Description |
|---|---|---|
| name | String | cookie name |
Return
| Type | Description |
|---|---|
| Cookie | found cookie, Nil otherwise |
GetCookies #
Gets the cookies
method : public : GetCookies() ~ Vector<Cookie>Return
| Type | Description |
|---|---|
| Vector<Cookie> | vector of cookies |
Example
client := Web.HTTP.HttpClient->New(true);
client->Get(Web.HTTP.Url->New("https://httpbin.org/cookies/set/session/abc"));
cookies := client->GetCookies();
each(c in cookies) {
c->GetName()->PrintLine();
};GetRequestHeaders #
Gets the HTTP request headers
method : public : GetRequestHeaders() ~ Hash<String,String>Return
| Type | Description |
|---|---|
| Hash<String,String> | HTTP request headers |
GetResponseHeaders #
Gets the HTTP response headers
method : public : GetResponseHeaders() ~ Hash<String,String>Return
| Type | Description |
|---|---|
| Hash<String,String> | HTTP response headers |
HasCookie #
Checks for a cookie
method : public : HasCookie(name:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | cookie name |
Return
| Type | Description |
|---|---|
| Bool | true if found cookie, false otherwise |
New # constructor
Default constructor
New(cookies_enabled:Bool)Parameters
| Name | Type | Description |
|---|---|---|
| cookies_enabled | Bool | true if cookies are enabled, false otherwise |
Patch #
Performs a HTTP PATCH
method : public : Patch(url:Web.HTTP.Url, data:Byte[]) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to patch |
Return
| Type | Description |
|---|---|
| Response | string read |
Example
client := Web.HTTP.HttpClient->New();
body := "{\"status\":\"active\"}"->ToByteArray();
response := client->Patch(Web.HTTP.Url->New("https://api.example.com/users/5"), body);
response->GetStatusCode()->PrintLine();Patch #
Performs a HTTP PATCH
method : public : Patch(url:Web.HTTP.Url, data:Byte[], content_type:String) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to patch |
| content_type | String | content type |
Return
| Type | Description |
|---|---|
| Response | string read |
Post #
Performs a HTTPS POST
method : public : Post(url:Web.HTTP.Url, data:Byte[], content_type:String) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to oper |
| content_type | String | content type |
Return
| Type | Description |
|---|---|
| Response | string read |
Example
client := Web.HTTP.HttpClient->New();
body := "{\"user\":\"bob\",\"score\":42}"->ToByteArray();
response := client->Post(
Web.HTTP.Url->New("https://api.example.com/scores"),
body,
"application/json");
response->GetStatusCode()->PrintLine();Post #
Performs a HTTP POST
method : public : Post(url:Web.HTTP.Url, data:Byte[]) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
Return
| Type | Description |
|---|---|
| Response | string read |
Example
client := Web.HTTP.HttpClient->New();
body := "{\"name\":\"Alice\"}"->ToByteArray();
response := client->Post(Web.HTTP.Url->New("https://httpbin.org/post"), body);
if(response <> Nil) {
response->GetStatusCode()->PrintLine();
};Put #
Performs a HTTP POST
method : public : Put(url:Web.HTTP.Url, data:Byte[]) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
Return
| Type | Description |
|---|---|
| Response | string read |
Example
client := Web.HTTP.HttpClient->New();
body := "{\"name\":\"Updated\"}"->ToByteArray();
response := client->Put(Web.HTTP.Url->New("https://api.example.com/items/1"), body);
response->GetStatusCode()->PrintLine();Put #
Performs a HTTP POST
method : public : Put(url:Web.HTTP.Url, data:Byte[], content_type:String) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
| content_type | String | content type |
Return
| Type | Description |
|---|---|
| Response | string read |
QuickDelete # function
Performs a HTTP DELETE and returns results as a String
function : QuickDelete(url:Web.HTTP.Url) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
Return
| Type | Description |
|---|---|
| Response | output buffer |
QuickDelete # function
Performs a HTTP DELETE and returns results as a String
function : QuickDelete(url:Web.HTTP.Url, headers:Map<String,String>) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| headers | Map<String,String> | key/value headers |
Return
| Type | Description |
|---|---|
| Response | output buffer |
QuickDelete # function
Performs a HTTP DELETE and returns results as a String
function : QuickDelete(url:Web.HTTP.Url, content_type:String) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| content_type | String | content type |
Return
| Type | Description |
|---|---|
| Response | output buffer |
QuickDelete # function
Performs a HTTP DELETE and returns results as a String
function : QuickDelete(url:Web.HTTP.Url, content_type:String, headers:Map<String,String>) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| content_type | String | content type |
| headers | Map<String,String> | key/value headers |
Return
| Type | Description |
|---|---|
| Response | output buffer |
QuickDelete # function
Performs a HTTP DELETE and returns results as a String
function : QuickDelete(url:Web.HTTP.Url, data:Byte[]) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
Return
| Type | Description |
|---|---|
| Response | output buffer |
QuickDelete # function
Performs a HTTP DELETE and returns results as a String
function : QuickDelete(url:Web.HTTP.Url, data:Byte[], headers:Map<String,String>) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
| headers | Map<String,String> | key/value headers |
Return
| Type | Description |
|---|---|
| Response | output buffer |
QuickDelete # function
Performs a HTTP DELETE and returns results as a String
function : QuickDelete(url:Web.HTTP.Url, data:Byte[], content_type:String) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
| content_type | String | content type |
Return
| Type | Description |
|---|---|
| Response | output buffer |
QuickDelete # function
Performs a HTTP DELETE and returns results as a String
function : QuickDelete(url:Web.HTTP.Url, data:Byte[], content_type:String, headers:Map<String,String>) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
| content_type | String | content type |
| headers | Map<String,String> | key/value headers |
Return
| Type | Description |
|---|---|
| Response | output buffer |
QuickGet # function
Performs a HTTP GET and returns results as a String
function : QuickGet(url:Web.HTTP.Url) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
Return
| Type | Description |
|---|---|
| Response | output buffer |
Example
response := Web.HTTP.HttpClient->QuickGet(Web.HTTP.Url->New("https://httpbin.org/get"));
if(response <> Nil) {
response->ToString()->PrintLine();
};QuickGet # function
Performs a HTTP GET and returns results as a String
function : QuickGet(url:Web.HTTP.Url, headers:Map<String,String>) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| headers | Map<String,String> | key/value headers |
Return
| Type | Description |
|---|---|
| Response | output buffer |
Example
hdrs := Collection.Map->New()<String, String>;
hdrs->Insert("Accept", "application/json");
response := Web.HTTP.HttpClient->QuickGet(Web.HTTP.Url->New("https://api.example.com"), hdrs);
response->ToString()->PrintLine();QuickGet # function
Performs a HTTP GET and returns results as a String
function : QuickGet(url:Web.HTTP.Url, content_type:String) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| content_type | String | content type |
Return
| Type | Description |
|---|---|
| Response | output buffer |
QuickGet # function
Performs a HTTP GET and returns results as a String
function : QuickGet(url:Web.HTTP.Url, content_type:String, headers:Map<String,String>) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| content_type | String | content type |
| headers | Map<String,String> | key/value headers |
Return
| Type | Description |
|---|---|
| Response | output buffer |
QuickPatch # function
Performs a HTTP PATCH
function : QuickPatch(url:Web.HTTP.Url, data:Byte[]) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to patch |
Return
| Type | Description |
|---|---|
| Response | read strings |
QuickPatch # function
Performs a HTTP PATCH
function : QuickPatch(url:Web.HTTP.Url, data:Byte[], content_type:String) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to patch |
| content_type | String | content type |
Return
| Type | Description |
|---|---|
| Response | read strings |
QuickPatch # function
Performs a HTTP PATCH
function : QuickPatch(url:Web.HTTP.Url, data:Byte[], content_type:String, headers:Map<String,String>) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to patch |
| content_type | String | content type |
| headers | Map<String,String> | key/value headers |
Return
| Type | Description |
|---|---|
| Response | read strings |
QuickPost # function
Performs a HTTP POST
function : QuickPost(url:Web.HTTP.Url, data:Byte[]) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
Return
| Type | Description |
|---|---|
| Response | read strings |
Example
body := "{\"event\":\"click\"}"->ToByteArray();
response := Web.HTTP.HttpClient->QuickPost(Web.HTTP.Url->New("https://httpbin.org/post"), body);
response->GetStatusCode()->PrintLine();QuickPost # function
Performs a HTTPS POST
function : QuickPost(url:Web.HTTP.Url, data:Byte[], content_type:String) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
| content_type | String | content type |
Return
| Type | Description |
|---|---|
| Response | read strings |
Example
body := "{\"x\":1}"->ToByteArray();
response := Web.HTTP.HttpClient->QuickPost(
Web.HTTP.Url->New("https://api.example.com/events"),
body,
"application/json");
response->GetStatusCode()->PrintLine();QuickPost # function
Performs a HTTP POST
function : QuickPost(url:Web.HTTP.Url, data:Byte[], content_type:String, headers:Map<String,String>) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
| content_type | String | content type |
| headers | Map<String,String> | key/value headers |
Return
| Type | Description |
|---|---|
| Response | read strings |
QuickPut # function
Performs a HTTP POST
function : QuickPut(url:Web.HTTP.Url, data:Byte[]) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
Return
| Type | Description |
|---|---|
| Response | read strings |
QuickPut # function
Performs a HTTPS POST
function : QuickPut(url:Web.HTTP.Url, data:Byte[], content_type:String) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
| content_type | String | content type |
Return
| Type | Description |
|---|---|
| Response | read strings |
QuickPut # function
Performs a HTTP POST
function : QuickPut(url:Web.HTTP.Url, data:Byte[], content_type:String, headers:Map<String,String>) ~ Web.HTTP.ResponseParameters
| Name | Type | Description |
|---|---|---|
| url | Url | URL |
| data | Byte | data to post |
| content_type | String | content type |
| headers | Map<String,String> | key/value headers |
Return
| Type | Description |
|---|---|
| Response | read strings |
RemoveHeader #
Removes a HTTP request header
method : public : RemoveHeader(name:String) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| name | String | header name |
Example
client := Web.HTTP.HttpClient->New();
client->AddHeader("X-Debug", "1");
# remove before production call
client->RemoveHeader("X-Debug");SetCookie #
Sets a cookie
method : public : SetCookie(cookie:Cookie) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| cookie | Cookie | cookie |
SetMaxRedirects #
Sets the maximum number of redirects to follow (default 10)
method : public : SetMaxRedirects(max:Int) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| max | Int | maximum redirects |
Example
client := Web.HTTP.HttpClient->New();
client->SetMaxRedirects(3);SetRetry #
Sets retry behavior for transient errors (429, 503)
method : public : SetRetry(max_retries:Int, delay_ms:Int) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| max_retries | Int | maximum retry attempts (default 3, 0 to disable) |
| delay_ms | Int | initial delay between retries in milliseconds (default 1000, doubles each retry) |
Example
client := Web.HTTP.HttpClient->New();
client->SetRetry(3, 500); # retry up to 3 times, 500ms between attempts
response := client->Get(Web.HTTP.Url->New("https://api.example.com/items"));