Files
hyper/examples
Sean McArthur 30870029b9 feat(server): change NewService to MakeService with connection context
This adjusts the way `Service`s are created for a `hyper::Server`. The
`MakeService` trait allows receiving an argument when creating a
`Service`. The implementation for `hyper::Server` expects to pass a
reference to the accepted transport (so, `&Incoming::Item`). The user
can inspect the transport before making a `Service`.

In practice, this allows for things like getting the remote socket
address, or the TLS certification, or similar.

To prevent a breaking change, there is a blanket implementation of
`MakeService` for any `NewService`. Besides implementing `MakeService`
directly, there is also added `hyper::service::make_service_fn`.

Closes #1650
2018-11-16 13:18:09 -08:00
..
2018-10-02 10:07:31 -07:00
2018-10-16 13:21:45 -07:00

Examples of using hyper

Run examples with cargo run --example example_name.

Available examples

  • 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.

  • echo - An echo server that copies POST request's content to the response content.

  • hello - A simple server that returns "Hello World!" using a closure wrapped to provide a Service.

  • multi_server - A server that listens to two different ports, a different Service by port, spawning two futures.

  • params - A webserver that accept a form, with a name and a number, checks the parameters are presents and validates the input.

  • proxy - A webserver that proxies to the hello service above.

  • send_file - A server that sends back content of files using tokio_fs to read the files asynchronously.

  • single_threaded - A server only running on 1 thread, so it can make use of !Send app state (like an Rc counter).

  • 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 or CONNECT tunneling).

  • web_api - A server consisting in a service that returns incoming POST request's content in the response in uppercase and a service that call that call the first service and includes the first service response in its own response.