Examples of using hyper
These examples show of how to do common tasks using hyper. You may also find the Guides helpful.
If you checkout this repository, you can run any of the examples cargo run --example example_name.
Dependencies
Most of these examples use these dependencies:
[dependencies]
hyper = { version = "0.14", features = ["full"] }
tokio = { version = "1", features = ["full"] }
pretty_env_logger = "0.4"
Getting Started
Clients
-
client- A simple CLI http client that request the url passed in parameters and outputs the response content and details to the stdout, reading content chunk-by-chunk. -
client_json- A simple program that GETs some json, reads the body asynchronously, parses it with serde and outputs the result.
Servers
-
hello- A simple server that returns "Hello World!". -
echo- An echo server that copies POST request's content to the response content.
Going Further
-
gateway- A server gateway (reverse proxy) that proxies to thehelloservice above. -
http_proxy- A simple HTTP(S) proxy that handle and upgradeCONNECTrequests and then proxy data between client and remote server. -
multi_server- A server that listens to two different ports, a differentServiceper port. -
params- A webserver that accept a form, with a name and a number, checks the parameters are presents and validates the input. -
send_file- A server that sends back content of files using tokio-util to read the files asynchronously. -
service_struct_impl- A struct that manually implements theServicetrait and uses a shared counter across requests. -
single_threaded- A server only running on 1 thread, so it can make use of!Sendapp state (like anRccounter). -
state- A webserver showing basic state sharing among requests. A counter is shared, incremented for every request, and every response is sent the last count. -
upgrades- A server and client demonstrating how to do HTTP upgrades (such as WebSockets). -
web_api- A server consisting in a service that returns incoming POST request's content in the response in uppercase and a service that calls the first service and includes the first service response in its own response.