5 ms·
A couple weeks ago I sat down with this and tried to build a simple client for an HTTP API. Three hours later, having read about all sorts of prebuilt proprieta
by ctoth 5y ago
A couple weeks ago I sat down with this and tried to build a simple client for an HTTP API. Three hours later, having read about all sorts of prebuilt proprietary components without being able to try writing any code at all I gave up. Can anyone point me towards a library that will help me make somewhat-complex HTTP Requests on this platform? Something more than GET, that allows me to set headers?
- gfody 5y agohttps://github.com/isemenkov/libpascurl https://github.com/isemenkov/libpascurl
- tomc1985 5y agohttps://wiki.freepascal.org/fphttpclient https://wiki.freepascal.org/fphttpclient isn't good enough? Why do you need a library?
- thijsvandien 5y agoIndy is very popular, especially among Delphi users (shipped with it): https://github.com/IndySockets/Indy https://github.com/IndySockets/Indy.
- edwinyzh 5y agohttps://github.com/synopse/mORMot2 https://github.com/synopse/mORMot2 Very rich and mature feature-set, with active development and active user forums.
- lmz 5y agoIt just seems very odd that (2!) people would recommend an "ORM/SOA framework" when all the poster wanted was an HTTP client library. At least you can link to the HTTP client parts?
- clouddrover 5y agoHere you go: Mormot 1.18 (stable): https://github.com/synopse/mORMot/blob/master/SynCrtSock.pas https://github.com/synopse/mORMot/blob/master/SynCrtSock.pas Mormot 2: https://github.com/synopse/mORMot2/blob/master/src/net/mormot.net.client.pas https://github.com/synopse/mORMot2/blob/master/src/net/mormo... https://synopse.info/files/html/api-1.18/SynCrtSock.html#THTTPCLIENTSOCKET https://synopse.info/files/html/api-1.18/SynCrtSock.html#THT... https://synopse.info/files/html/Synopse%20mORMot%20Framework%20SAD%201.18.html#TITL_135 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).
- benibela 5y agoIt is because Lazarus/FPC have no package manager to handle dependencies. It is crippling the ecosystem. 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.
- revanx_ 5y agoI use the synopse mORMot library for server side rendering http server and database access. It has well written documentation with lots of examples on how to get started. IF you have any questions I am free to answer them.
- ziotom78 5y agoI had the very same experience, and ended up using the wikipage posted above. But I had to fix it because there were some outdated information. 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.)
- benibela 5y agoI wrote my own library for that: https://github.com/benibela/internettools https://github.com/benibela/internettools 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.
- ale42 5y agoThose days I'm using libcurl with the bindings that are supplied with Lazarus/FPC... works perfectly fine (tested on Windows and Linux, I suppose MacOS will work too... on Windows you need to install the DLL, e.g. libcurl-x64.dll). No need to install anything on Lazarus/FPC. Below a basic (incomplete) example of a GET request with a custom header, but as this is just a binding to libcurl, it basically allows you to do anything, including other protocols (libcurl can even have SMTP support, depending how it is compiled). 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.