Jump to page: 1 2
Thread overview
both std.net.curl and hunt http clients fail
Jun 12
drenoob
Jun 12
drenoob
Jun 12
Serg Gini
Jun 12
drenoob
Jun 12
Serg Gini
Jun 12
drenoob
Jun 12
monkyyy
Jun 12
drenoob
Jun 12
Sergey
Jun 13
drenoob
Jun 12
drenoob
Jun 12
drenoob
June 12

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/Collections.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/BigInteger.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/Collections.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/Collections.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/HttpSession.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/Collections.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

June 12

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.

June 12

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.
June 12

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
}
June 12

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!

June 12

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!

June 12

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

June 12

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!

June 12

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.

June 13
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.

« First   ‹ Prev
1 2