Requires: libcurl (auto-installed via minks install kse_curl)
#include "kse_curl"
| Method | Args | Out | Description |
|---|---|---|---|
Curl:Get |
url |
String | HTTP GET → response body |
Curl:Post |
url, body |
String | HTTP POST with body |
Curl:Put |
url, body |
String | HTTP PUT with body |
Curl:Delete |
url |
String | HTTP DELETE |
Curl:Status |
- | Number | HTTP status code of last request |
Curl:SetHeader |
key, value |
void | Set a persistent request header |
Curl:ClearHeaders |
- | void | Remove all set headers |
Curl:SetTimeout |
seconds |
void | Request timeout (default: 30) |
Curl:Download |
url, user, pass, localPath |
Boolean | FTP/HTTP download; response streamed to local file (binary-safe, any size); throws CurlException on failure |
Curl:Upload |
url, user, pass, localPath |
Boolean | FTP upload; local file streamed to remote path (binary-safe, any size); throws CurlException on failure |
Curl:OnProgress |
fn |
void | Register a progress callback for Upload/Download; fn(Number done, Number total) |
Throws CurlException on failure (auth, connection, transfer, etc.). See Object - Exception.
Curl:SetHeader("Authorization", "Bearer mytoken");
Curl:SetHeader("Accept", "application/json");
Var:String body;
Var:Number status;
try {
Curl:Get("https://api.example.com/users", body);
} catch (CurlException e) {
Konsol:Print("curl error: ${e.message}");
}
Curl:Status(status);
Konsol:Print("${status}: ${body}");
Curl:ClearHeaders();
FTP example:
// Download
Var:String listing
Curl:Get("ftp://192.168.1.10/files/", listing)
Konsol:Print(listing)
// Download to local file (text or binary)
Var:Boolean ok
try {
Curl:Download("ftp://192.168.1.10/releases/app.zip", "admin", "secret", "local/app.zip", ok)
Konsol:Print("download OK")
} catch (CurlException e) {
Konsol:Print("download failed: ${e.message}")
}
// Upload (text or binary - pass local file path)
Var:Boolean ok
try {
Curl:Upload("ftp://192.168.1.10/uploads/report.txt", "admin", "secret", "local/report.txt", ok)
Konsol:Print("upload OK")
} catch (CurlException e) {
Konsol:Print("upload failed: ${e.message}")
}
Progress callback example:
function onProgress(Number done, Number total) {
if (total > 0) {
Var:Number pct = done * 100 / total
Konsol:Print("${pct}%")
}
}
Curl:OnProgress(onProgress)
Var:Boolean ok
Curl:Download("ftp://192.168.1.10/releases/app.zip", "admin", "secret", "app.zip", ok)
Curl:OnProgress("") // clear callback when done
| Platform | Command |
|---|---|
| Debian/Ubuntu | sudo apt install libcurl4-openssl-dev |
| Fedora/RHEL | sudo dnf install libcurl-devel |
| macOS | brew install curl |
| MSYS2 MINGW64 | pacman -S mingw-w64-x86_64-curl |
| MSYS2 UCRT64 | pacman -S mingw-w64-ucrt-x86_64-curl |
| MSYS2 CLANG64 | pacman -S mingw-w64-clang-x86_64-curl |
| MSYS2 CLANGARM64 | pacman -S mingw-w64-clang-aarch64-curl |
The Makefile auto-detects via pkg-config.
make -C curl_plugin
// test_curl.ks - Curl plugin tests
// Requires network access; uses httpbin.org as echo server.
//
// After installing:
// minks install kse_curl (run once from inside curl_plugin/)
// minks test_curl.ks
//
// Without installing (load from current directory):
// minks --plugin-path . test_curl.ks
#include "kse_curl"
Konsol:Print("=== Curl plugin ===");
Var:String body;
Var:Number code;
// ── GET ────────────────────────────────────────────────────────────────────────
Konsol:Print("--- GET");
Curl:Get("https://httpbin.org/get", body);
Curl:Status(code);
Konsol:Print("status : ${code}");
Konsol:Print("body : ${body}");
// ── POST ───────────────────────────────────────────────────────────────────────
Konsol:Print("--- POST");
Curl:Post("https://httpbin.org/post", "hello=world&lang=minks", body);
Curl:Status(code);
Konsol:Print("status : ${code}");
Konsol:Print("body : ${body}");
// ── PUT ────────────────────────────────────────────────────────────────────────
Konsol:Print("--- PUT");
Curl:Put("https://httpbin.org/put", "{\"key\":\"value\"}", body);
Curl:Status(code);
Konsol:Print("status : ${code}");
Konsol:Print("body : ${body}");
// ── DELETE ─────────────────────────────────────────────────────────────────────
Konsol:Print("--- DELETE");
Curl:Delete("https://httpbin.org/delete", body);
Curl:Status(code);
Konsol:Print("status : ${code}");
Konsol:Print("body : ${body}");
// ── Custom headers ─────────────────────────────────────────────────────────────
Konsol:Print("--- custom headers");
Curl:SetHeader("X-Test-Header", "minks-curl");
Curl:SetHeader("Accept", "application/json");
Curl:Get("https://httpbin.org/headers", body);
Curl:Status(code);
Konsol:Print("status : ${code}");
Konsol:Print("body : ${body}");
Curl:ClearHeaders();
// ── Status code passthrough ────────────────────────────────────────────────────
Konsol:Print("--- 404");
Curl:Get("https://httpbin.org/status/404", body);
Curl:Status(code);
Konsol:Print("status : ${code}");
Konsol:Print("--- 500");
Curl:Get("https://httpbin.org/status/500", body);
Curl:Status(code);
Konsol:Print("status : ${code}");
// ── Timeout ────────────────────────────────────────────────────────────────────
Konsol:Print("--- timeout (2s, then a real request)");
Curl:SetTimeout(2);
Curl:Get("https://httpbin.org/delay/5", body);
Curl:Status(code);
Konsol:Print("status after timeout : ${code}");
Curl:SetTimeout(30);
Curl:Get("https://httpbin.org/get", body);
Curl:Status(code);
Konsol:Print("status after restore : ${code}");
// ── Download to file ───────────────────────────────────────────────────────────
Konsol:Print("--- Download");
Var:Boolean ok;
try {
Curl:Download("https://httpbin.org/get", "", "", "test_download.txt", ok);
Curl:Status(code);
Konsol:Print("status : ${code}");
Konsol:Print("saved : ${ok}");
Var:Boolean exists;
File:Exists("test_download.txt", exists);
Konsol:Print("on disk : ${exists}");
Var:Number fh;
Var:String firstLine;
File:Open("test_download.txt", "r", fh);
File:ReadLine(fh, firstLine);
File:Close(fh);
Konsol:Print("line 1 : ${firstLine}");
File:Delete("test_download.txt", ok);
} catch (CurlException e) {
Konsol:Print("download failed: ${e.message}");
}
// ── FTP Upload (requires a local FTP server) ───────────────────────────────────
//
// Uncomment and adjust host/credentials to test against a real FTP server:
//
// Var:Number fh;
// File:Open("test_upload.txt", "w", fh);
// File:Write("hello from minks\n", fh);
// File:Close(fh);
//
// Var:Boolean uploadOk;
// try {
// Curl:Upload("ftp://127.0.0.1/uploads/test_upload.txt", "user", "pass", "test_upload.txt", uploadOk);
// Konsol:Print("ftp upload OK");
// } catch (CurlException e) {
// Konsol:Print("ftp upload failed: ${e.message}");
// }
//
// File:Delete("test_upload.txt", ok);
Konsol:Print("=== done ===");