www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - both std.net.curl and hunt http clients fail

reply drenoob <dlang none.org> writes:
Hello,

Finally re-discovering D again I wanted to try a small side 
project which largely is but an http[s] client. So, i tried first 
std.net.curl - and it failed. Then I tried the hunt lib - and it 
failed again.Note that in both cases I basically tried an example 
those libs provided.

Here's the curl code, in desperation slimmed down to an almost 
*verbatim copy* of their example:

     ------------ std.net.curl code --------------
      1|import std.net.curl, std.stdio;

      3|auto totLen = 0; // mine
      4|auto http = HTTP("https://some.url");
      5|http.onReceive = (ubyte[] data)
      6|{
      7|    /+ drop +/ totLen += data.length; // mine
      8|    return data.length;
      9|};
     10|http.onProgress = (size_t dltotal, size_t dlnow,
     11|                   size_t ultotal, size_t ulnow)
     12|{
     13|    writeln("Progress ", dltotal, ", ", dlnow, ", ", 
ultotal, ", ", ulnow);
     14|    return 0;
     15|};
     16|http.perform();
     // ---- End of code ---
the two lines I added or changed are commented '// mine''
the 'xx|' at the beginning of each line is the line number

This results in
  source/app.d(5,16): Error: variable name expected after type 
`http.onReceive`, not `=`
  http.onReceive = (ubyte[] data)
                    ^
  source/app.d(5,16): Error: declaration expected, not `=`
  http.onReceive = (ubyte[] data)
                    ^
  source/app.d(8,5): Error: `return` statement must be inside 
function scope
  return data.length;
  ^
  source/app.d(9,1): Error: unmatched closing brace
  };
  ^
  Error dmd failed with exit code 1.

======================= hunt lib ==============================
     import hunt.http;
     import std.stdio;

     enum tgtUrl = "https://some.url/";

     void main()
     {
         auto client = new HttpClient();
         auto request = new RequestBuilder().url(tgtUrl).build();
         auto response = client.newCall(request).execute();
         if (response !is null)
         {
             writeln("status code: %d", response.getStatus());
             writeln(response.getBody().asString());
         }
     }
     // ---- End of code ---
results in
../../.dub/packages/hunt-extra/1.2.3/hunt-extra/source/hunt/collection/Co
lections.d(157,19): Deprecation: a function template is not virtual so cannot
be marked `override`
     override bool contains(E)(E o) {return o == element;}
                   ^
../../.dub/packages/hunt-extra/1.2.3/hunt-extra/source/hunt/math/Bi
Integer.d(1242,39): Deprecation: function `std.math.exponential.log` is
deprecated - `std.math.exponential.log` called with argument types `(int)`
matches both `log(real)`, `log(double)`, and `log(float)`. Cast argument to
floating point type instead.
     logCache[i] = std.math.log(i);
                               ^
Building hunt-net 0.7.1: building configuration [default]
../../.dub/packages/hunt-extra/1.2.3/hunt-extra/source/hunt/collection/Co
lections.d(157,19): Deprecation: a function template is not virtual so cannot
be marked `override`
     override bool contains(E)(E o) {return o == element;}
                   ^
Building hunt-http 0.8.2: building configuration [default]
../../.dub/packages/hunt-extra/1.2.3/hunt-extra/source/hunt/collection/Co
lections.d(157,19): Deprecation: a function template is not virtual so cannot
be marked `override`
     override bool contains(E)(E o) {return o == element;}
                   ^
../../.dub/packages/hunt-http/0.8.2/hunt-http/source/hunt/http/server/Ht
pSession.d(528,41): Deprecation: slice of static array temporary returned by
`toHexString(result)` assigned to longer lived variable `str`
     string str = toLower(toHexString(result));
                                     ^
Building app ~master: building configuration [application]
../../.dub/packages/hunt-extra/1.2.3/hunt-extra/source/hunt/collection/Co
lections.d(157,19): Deprecation: a function template is not virtual so cannot
be marked `override`
     override bool contains(E)(E o) {return o == element;}
                   ^
====================================================================

Sorry, dear colleagues, while I still presume D be a *stable* and 
really decent language and very much welcome the fact that at 
least many libraries are not version 0.0.[whatever small number] 
(so basically alpha or beta at best), I hope you can understand 
that this first experience isn't exactly strengthening my hopes 
for and trust in the D universe ...

Or did I make a total noob mistake? If so (or even if not) please 
kindly let me know how to get some decent http client working.

Btw. DMD and dub have been freshly installed and should be 
current.

Thank you
Jun 12
next sibling parent drenoob <dlang none.org> writes:
Apologies for the terribly misformated and obtrusive error 
messages of the 2nd part. I'll try my best to' earn and get used 
to this forums formatting.

Again, I'm sorry.
Jun 12
prev sibling next sibling parent reply Serg Gini <kornburn yandex.ru> writes:
On Thursday, 12 June 2025 at 13:16:13 UTC, drenoob wrote:
 Hello,
 Sorry, dear colleagues, while I still presume D be a *stable* 
 and really decent language and very much welcome the fact that 
 at least many libraries are not version 0.0.[whatever small 
 number] (so basically alpha or beta at best), I hope you can 
 understand that this first experience isn't exactly 
 strengthening my hopes for and trust in the D universe ...

 Or did I make a total noob mistake? If so (or even if not) 
 please kindly let me know how to get some decent http client 
 working.
Not sure about std.net.curl, but hunt library is abandoned and not recommended to use.
 Btw. DMD and dub have been freshly installed and should be 
 current.

 Thank you
I'm not sure about support of "on progress" in other libraries, but simple examples can be found in this repo: https://github.com/cyrusmsk/d_http_client_benchmark So some comments: 1) Arsd solution - now can have some difficulties with dub integration. But can be suggested solution if you are using other arsd libraries and OpenD compiler 2) Vibe solution - should be solid, but a bit heavy (probably will install some other dependencies). Can be suggested if you are planning to use Vibe.D framework 3) Requests - nice library, currently not maintained very actively, but should work. The main issue could be with the usage on Windows. So I would recommend to try this solution, if you are not on Windows.
Jun 12
parent reply drenoob <dlang none.org> writes:
On Thursday, 12 June 2025 at 13:55:35 UTC, Serg Gini wrote:
 On Thursday, 12 June 2025 at 13:16:13 UTC, drenoob wrote:
 Hello,
 Sorry, dear colleagues, while I still presume D be a *stable* 
 and really decent language and very much welcome the fact that 
 at least many libraries are not version 0.0.[whatever small 
 number] (so basically alpha or beta at best), I hope you can 
 understand that this first experience isn't exactly 
 strengthening my hopes for and trust in the D universe ...

 Or did I make a total noob mistake? If so (or even if not) 
 please kindly let me know how to get some decent http client 
 working.
Not sure about std.net.curl, but hunt library is abandoned and not recommended to use.
 Btw. DMD and dub have been freshly installed and should be 
 current.

 Thank you
I'm not sure about support of "on progress" in other libraries, but simple examples can be found in this repo: https://github.com/cyrusmsk/d_http_client_benchmark So some comments: 1) Arsd solution - now can have some difficulties with dub integration. But can be suggested solution if you are using other arsd libraries and OpenD compiler 2) Vibe solution - should be solid, but a bit heavy (probably will install some other dependencies). Can be suggested if you are planning to use Vibe.D framework 3) Requests - nice library, currently not maintained very actively, but should work. The main issue could be with the usage on Windows. So I would recommend to try this solution, if you are not on Windows.
So, I shouldn't trust libs that are in the offical dub repo? Strange and sad.. But I'll certainly look at the link you provided and try what you told me. Thank you! Btw, can anyone point me to a guide re. this forum, you know, how to format things, how to put code, etc. And thanks also, for re-strengthening my hope for and assumption that D probably is what I'm looking for since so long!
Jun 12
next sibling parent reply Serg Gini <kornburn yandex.ru> writes:
On Thursday, 12 June 2025 at 14:36:41 UTC, drenoob wrote:
 Btw, can anyone point me to a guide re. this forum, you know, 
 how to format things, how to put code, etc.
https://forum.dlang.org/help#about It should support Markdown
Jun 12
next sibling parent drenoob <dlang none.org> writes:
On Thursday, 12 June 2025 at 14:41:24 UTC, Serg Gini wrote:
 On Thursday, 12 June 2025 at 14:36:41 UTC, drenoob wrote:
 Btw, can anyone point me to a guide re. this forum, you know, 
 how to format things, how to put code, etc.
https://forum.dlang.org/help#about It should support Markdown
Yes, this looks like what I was looking for. Thanks again!
Jun 12
prev sibling parent monkyyy <crazymonkyyy gmail.com> writes:
On Thursday, 12 June 2025 at 14:41:24 UTC, Serg Gini wrote:
 On Thursday, 12 June 2025 at 14:36:41 UTC, drenoob wrote:
 Btw, can anyone point me to a guide re. this forum, you know, 
 how to format things, how to put code, etc.
https://forum.dlang.org/help#about It should support Markdown
Its table behavior isnt in github markdown spec like it claims
Jun 12
prev sibling parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 13/06/2025 2:36 AM, drenoob wrote:
 So, I shouldn't trust libs that are in the offical dub repo? Strange and 
 sad..
The dub registry is no different than nuget's or npm's. Unless its shipped with the compiler it is naturally lower (if any) trust.
Jun 12
parent reply drenoob <dlang none.org> writes:
On Thursday, 12 June 2025 at 15:24:35 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
 On 13/06/2025 2:36 AM, drenoob wrote:
 So, I shouldn't trust libs that are in the offical dub repo? 
 Strange and sad..
The dub registry is no different than nuget's or npm's. Unless its shipped with the compiler it is naturally lower (if any) trust.
Well, I guess I learned that now. But then: *is* there a place where one can find stable/mature/maintained and/or trustworthy D libs? OK, in my case falling for a, let me call it questionable, lib was desastrous because *of course* it makes a language look not exactly great when right at the get-go one walks into a "trap". But I guess I'm not the only one who, to a major degree came to D because I wanted a *mature* tool (and "universe"), and probably quite many would value a place where one hadn't to play lottery but could find reasonably reliable libs. Btw, are there any more or less agreed upon standards re (lib) docu here in the D-lang community? I'm asking because that (largely non existing lib docu) was one of the major reasons I gave up on another language with plenty "funny" experiments but precious little one could actually work with wrt docu (and rely upon). Be that as it may, I thank you.
Jun 12
parent reply Sergey <kornburn yandex.ru> writes:
On Thursday, 12 June 2025 at 16:00:20 UTC, drenoob wrote:
 Btw, are there any more or less agreed upon standards re (lib) 
 docu here in the D-lang community? I'm asking because that 
 (largely non existing lib docu) was one of the major reasons I 
 gave up on another language with plenty "funny" experiments but 
 precious little one could actually work with wrt docu (and rely 
 upon).

 Be that as it may, I thank you.
I'm not sure what do you mean.. Did you check the official web-site? There are a lot of docs regarding the language and standard library (name Phobos): https://dlang.org/spec/spec.html https://dlang.org/phobos/index.html Regarding docs for 3rd party libs - it depends on the author of the lib - if provide the documentation. Usually they are putting some description into github or separate page. You can search them here: https://code.dlang.org There is no "recommended and maintained list of packages". DLF doesn't want to do that.. Mostly because D doesn't have any resources.. It is trying to do the best with almost 0 resources. So I would recommend just to ask here in "Learn" place or come to Discord and ask there which library you want. Search functionality on dub is working.. but working pretty badly and has several issues But Discord people know **all packages** that D's ecosystem has - so they will help you with any request :)
Jun 12
parent drenoob <dlang none.org> writes:
On Thursday, 12 June 2025 at 21:13:31 UTC, Sergey wrote:
 I'm not sure what do you mean..
 Did you check the official web-site?
 There are a lot of docs regarding the language and standard 
 library (name Phobos):

 https://dlang.org/spec/spec.html
 https://dlang.org/phobos/index.html
I didn't doubt the "quality of the on board batteries" of D but of (some? many?) third party libraries.
 Regarding docs for 3rd party libs - it depends on the author of 
 the lib - if provide the documentation. Usually they are 
 putting some description into github or separate page.

 You can search them here: https://code.dlang.org

 There is no "recommended and maintained list of packages".
 DLF doesn't want to do that.. Mostly because D doesn't have any 
 resources..
 It is trying to do the best with almost 0 resources.
 So I would recommend just to ask here in "Learn" place or come 
 to Discord and ask there which library you want.
 Search functionality on dub is working.. but working pretty 
 badly and has several issues
 But Discord people know **all packages** that D's ecosystem has 
 - so they will help you with any request :)
Thank you
Jun 13
prev sibling next sibling parent reply Lance Bachmeier <no spam.net> writes:
On Thursday, 12 June 2025 at 13:16:13 UTC, drenoob wrote:

[...]

 Sorry, dear colleagues, while I still presume D be a *stable* 
 and really decent language and very much welcome the fact that 
 at least many libraries are not version 0.0.[whatever small 
 number] (so basically alpha or beta at best), I hope you can 
 understand that this first experience isn't exactly 
 strengthening my hopes for and trust in the D universe ...

 Or did I make a total noob mistake? If so (or even if not) 
 please kindly let me know how to get some decent http client 
 working.

 Btw. DMD and dub have been freshly installed and should be 
 current.

 Thank you
Well, this is actually a problem of the documentation omitting a critical detail. If you run that code inside a function, it works: ``` void main() { // Insert all of your code here } ```
Jun 12
next sibling parent drenoob <dlang none.org> writes:
On Thursday, 12 June 2025 at 14:32:07 UTC, Lance Bachmeier wrote:
 On Thursday, 12 June 2025 at 13:16:13 UTC, drenoob wrote:
 Well, this is actually a problem of the documentation omitting 
 a critical detail. If you run that code inside a function, it 
 works:

 ```
 void main() {
  // Insert all of your code here
 }
 ```
I'll try that as well. Thank you!
Jun 12
prev sibling parent drenoob <dlang none.org> writes:
On Thursday, 12 June 2025 at 14:32:07 UTC, Lance Bachmeier wrote:
 On Thursday, 12 June 2025 at 13:16:13 UTC, drenoob wrote:

 [...]

 Sorry, dear colleagues, while I still presume D be a *stable* 
 and really decent language and very much welcome the fact that 
 at least many libraries are not version 0.0.[whatever small 
 number] (so basically alpha or beta at best), I hope you can 
 understand that this first experience isn't exactly 
 strengthening my hopes for and trust in the D universe ...

 Or did I make a total noob mistake? If so (or even if not) 
 please kindly let me know how to get some decent http client 
 working.

 Btw. DMD and dub have been freshly installed and should be 
 current.

 Thank you
Well, this is actually a problem of the documentation omitting a critical detail. If you run that code inside a function, it works: ``` void main() { // Insert all of your code here } ```
Yep, now it suddenly works. Hurray! Thanks a lot! P.S. But I'll have a closer look at the requestes lib suggested by Serg Gini as well, because it look interesting.
Jun 12
prev sibling parent Dejan Lekic <dejan.lekic gmail.com> writes:
On Thursday, 12 June 2025 at 13:16:13 UTC, drenoob wrote:
 Sorry, dear colleagues, while I still presume D be a *stable* 
 and really decent language and very much welcome the fact that 
 at least many libraries are not version 0.0.[whatever small 
 number] (so basically alpha or beta at best), I hope you can 
 understand that this first experience isn't exactly 
 strengthening my hopes for and trust in the D universe ...
If you expected http client to be in the standard library - you expected too much. C/C++/Rust do not have it either for a reason - it would expand the standard library too much (assuming it covers everything). Whenever I had to do http requests I used the excellent dlang-requests library ( https://github.com/ikod/dlang-requests ). It was a natural choice as I do Python programming on a daily basis... dlang-requests is in my top 10 list of all D packages just like Python `requests` package is in my top 10 Python packages. Highly recommended.
Jun 13