Hyper: Example client examples for hyper

Created on 21 Sep 2018  路  4Comments  路  Source: hyperium/hyper

Hi,

I'm trying to learn to use hyper for a program, but I'm finding that the api docs (whchi are very detailed) are really dense and hard to access. At the same time, I'm seeing that the examples folder is really light on client examples IE POST json to a server or otherwise.

It would be great if the client examples were expanded to help make some of these concepts clearer, especially around the construction of requests and the future types.

Thanks!

A-client A-docs

Most helpful comment

I feel your pain and I also miss a lot more guide docs and a lot more examples about clients in hyper (either synchronously and asynchronously).
I'm a newcomer and I've already spent a day trying to start N client requests with hyper. Still struggling...

The first headache I've encountered is that the docs only says:

"By default, hyper can make use of the Tokio runtime, via hyper::rt"

And that's all about it. What is a Tokio runtime? How do I start it? Why there is no snippet showing how to start it in the guide docs?
All it has are these comments:

// still inside rt::run...

At the end of the guide, we also have this:

And that鈥檚 it! You can see the full example here.

There are only 2 examples there: client.rs and client_json.rs

Reading them I finally discover that I need to run hyper::rt::run(my_future);

Ok... got it and it works (for 1 future only). But how about an example or a guide section showing how to run N client futures? And what if we want them to run syncronously or asyncronously? After a long reading about Tokio Futures, I've discovered about .wait() and .join()... but those doesn't fit well with hyper::rt::run I guess ... do I need to use tokio::run instead? I have no clue...

All 4 comments

+1
I miss example, how to create a client for https url with custom header (Token Authorization) and save result from future to string. The examples are very limited.

Another example that would be useful is how to correctly use status codes to then provide logic of how to decode json for example, as the use of futures and their integration with these libraries is not always clear. Having a reference written by experts is really useful as a lesson for inexperienced futures users like myself to understand the right way to use these.

I feel your pain and I also miss a lot more guide docs and a lot more examples about clients in hyper (either synchronously and asynchronously).
I'm a newcomer and I've already spent a day trying to start N client requests with hyper. Still struggling...

The first headache I've encountered is that the docs only says:

"By default, hyper can make use of the Tokio runtime, via hyper::rt"

And that's all about it. What is a Tokio runtime? How do I start it? Why there is no snippet showing how to start it in the guide docs?
All it has are these comments:

// still inside rt::run...

At the end of the guide, we also have this:

And that鈥檚 it! You can see the full example here.

There are only 2 examples there: client.rs and client_json.rs

Reading them I finally discover that I need to run hyper::rt::run(my_future);

Ok... got it and it works (for 1 future only). But how about an example or a guide section showing how to run N client futures? And what if we want them to run syncronously or asyncronously? After a long reading about Tokio Futures, I've discovered about .wait() and .join()... but those doesn't fit well with hyper::rt::run I guess ... do I need to use tokio::run instead? I have no clue...

I know this is not a real answer but at least I can share what helped me to figure out how to use hyper client.

Reqwest is a higher level implementation based on top of hyper. Looking at its source helped me a lot.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

seanmonstar picture seanmonstar  路  3Comments

zonyitoo picture zonyitoo  路  4Comments

gabisurita picture gabisurita  路  4Comments

toplinuxsir picture toplinuxsir  路  3Comments

belst picture belst  路  3Comments