uses libcurl;
function curl_callback(data: pointer; size: size_t; nmemb: size_t; str: PStream): size_t; cdecl;
begin
// do something with incoming data
end;
var http: pCurl;
hdr: Pcurl_slist;
begin
http := curl_easy_init();
// [...]
hdr := curl_slist_append(NIL, pchar('Authorization: Bearer ' + EncodeStringBase64(AUTH_TOKEN)));
curl_easy_setopt(http, CURLOPT_HTTPHEADER, [hdr]);
curl_easy_setopt(http, CURLOPT_WRITEFUNCTION, [@curl_callback]);
curl_easy_setopt(http, CURLOPT_URL, [pchar(API_URL)]);
// [...]
if (curl_easy_perform(http) <> CURLE_OK) then begin
// [...]
end;
end.It's not that Lazarus lacks features, the problem is that the documentation is lacking and scattered. I found that the best way to learn Lazarus is to refer to some good Delphi books, provided that they are not too recent. (The Internet Archive has a few.)
Mormot 1.18 (stable): https://github.com/synopse/mORMot/blob/master/SynCrtSock.pas
Mormot 2: https://github.com/synopse/mORMot2/blob/master/src/net/mormo...
https://synopse.info/files/html/api-1.18/SynCrtSock.html#THT...
https://synopse.info/files/html/Synopse%20mORMot%20Framework...
They have multiple client implementations. You can pick the one you like (THTTPClientSocket, TWinHTTP, TWinINET, TCurlHTTP, TWinHttpWebSocketClient).
If you want to write an oss ORM/SOA framework with HTTP, you cannot use a HTTP client library, because then people cannot compile your framework when they do not have the library installed. You can write in the documentation, they should install the library, but no one reads that. Also, if the library gets an update, it might not be compatible anymore.
So you need to bundle the HTTP client in your framework. Now you could write your own or fork one, but in either case you end up with a framework and its own HTTP client.
On Windows it is a wrapper around wininet and on Linux around another library Synapse.
The HTTP client is in the directory internet, the HTML/XPath parser in the directory data.