Overview
curl wraps libcurl — the most widely deployed HTTP client library in the world. It supports HTTP/1.1, HTTP/2, HTTPS/TLS, Basic and Bearer auth, file upload/download, cookies, redirects, and a reusable handle model for connection pooling.
Use curl when you need raw HTTP power beyond what the built-in http-client offers: multipart uploads, custom TLS settings, FTP, persistent connections, or fine-grained timeout control.
CLib package
Requires libcurl4-openssl-dev. Ubuntu/Debian: sudo apt install libcurl4-openssl-dev
Quick Start
uses curl;
var r := Get('https://api.github.com/repos/torvalds/linux');
if IsOK(r) then
WriteLn(r.Body)
else
WriteLn('Error ', r.StatusCode, ': ', r.Error);
GET / POST / PUT / DELETE
// Simple GET
var r := Get('https://httpbin.org/get');
// POST JSON
var r := PostJSON('https://api.example.com/users',
'{"name":"Alice","email":"alice@example.com"}');
// PUT JSON
var r := PutJSON('https://api.example.com/users/42',
'{"name":"Alice Updated"}');
// PATCH
var r := PatchJSON('https://api.example.com/users/42',
'{"email":"new@example.com"}');
// DELETE
var r := Delete('https://api.example.com/users/42');
WriteLn(r.StatusCode, ' — ', Length(r.Body), ' bytes');
Custom Headers
// Headers string: "Name: Value\nName2: Value2"
var headers := BuildHeaders([
'Authorization', 'Bearer my-token',
'X-Request-Id', '12345',
'Accept', 'application/json'
]);
var r := GetH('https://api.example.com/data', headers);
var r := PostJSONH('https://api.example.com/data', body, headers);
Authentication
// Basic auth
var r := GetBasicAuth('https://api.example.com/private', 'user', 'pass');
// Bearer token
var r := GetBearer('https://api.example.com/me', 'eyJhbGci...');
var r := PostJSONBearer('https://api.example.com/data', body, token);
File Transfer
// Download file
DownloadFile('https://example.com/report.pdf', '/tmp/report.pdf');
DownloadFileBearer('https://api.example.com/export.csv', '/tmp/export.csv', token);
// Upload via multipart form
var r := UploadFile('https://api.example.com/upload', '/tmp/photo.jpg', 'file');
// Upload with extra form fields
var r := UploadFileEx(
'https://api.example.com/upload',
'/tmp/photo.jpg', 'file',
'title=My Photo\ndescription=Vacation',
headers
);
Reusable Handle (connection pooling)
// One handle reuses TCP connections — much faster for many requests
var h := NewHandle;
SetTimeout(h, 10);
SetUserAgent(h, 'MyApp/1.0');
for I := 0 to Length(urls) - 1 do begin
var r := Perform(h, 'GET', urls[I], '', '', '');
WriteLn(urls[I], ' → ', r.StatusCode);
end;
FreeHandle(h);
URL Encoding
var encoded := URLEncode('hello world & more'); // hello+world+%26+more
var decoded := URLDecode(encoded);
Package Info
Version1.0.0
Typeclib
C Librarylibcurl
Authorgustavo
TCurlResponse
.StatusCode — HTTP status.Body — response body.Headers — raw headers.Error — error message.TotalTime — seconds elapsed
Functions
- Get / GetH
- Post / PostH
- PostJSON / PostJSONH
- PostJSONBearer
- Put / PutJSON
- Patch / PatchJSON
- Delete / DeleteH
- GetBasicAuth
- GetBearer
- DownloadFile
- DownloadFileBearer
- UploadFile
- UploadFileEx
- NewHandle / FreeHandle
- Perform
- SetTimeout
- SetFollowRedirects
- SetUserAgent
- SetInsecure
- SetCookie
- URLEncode / URLDecode
- BuildHeaders
- IsOK
- CurlVersion
See Also
- http-client (simpler)
- websocket
- oauth2
- zmq