Working with Hyper library for http server

Hi everyone.
I'm making my way through creating http server using hyper lib and here is what i encountered with:
The Documentation gives the information about hyper::server::Response type. It says that there is send() method to create body and send the response to a request; But there is no such method for it when i code it. Is there any alternate way????

A hyper server is done by implementing its NewService trait: hyper::server::NewService - Rust

NewService is essentially a factory that creates a fresh implementation (per client connection) of something that implements the Service trait: hyper::server::Service - Rust

The Service impl you provide is the core of your server - that’s where you receive a request and then return some Future impl that contains the response. A simple example is hyper::server::Service - Rust. This example also shows how you set the body of the response.

Once you’ve defined impls for the above, you bootstrap the server with hyper::server::Http - Rust.

That was quite a piece of information Sir. Looks like things are getting more complicated. I was going through the Routing with hyper server, and i cant even emagine how to send a response to a routing request. I can only guess: I have to declare a handler for routing with .using(fn_name)... where i will create an instance that impls a Service trait and to call the call(rec:http::Request) that will send an immediate future Response? It will be undoubtfully great to get some coding example of a routing handler for hyper server to Respond on a Request.

Here's a small example of a server doing routing and different response styles (including holding the connection and pushing data down the stream).

It's sadly undocumented, I wrote it for a training.

https://github.com/skade/hyper-server/blob/master/src/main.rs

If you need more than basic routing (and other framework features common to a web server), you may want to look at higher level libs/frameworks than hyper. For example:

  1. iron + its iron router crate
  2. gotham
  3. rocket (note that rocket requires the nightly compiler)

#1 and #2 build on top of hyper. There may be others, but the above are ones I'm aware of offhand.

If you need more than routing (websockets, http/2) , Another high level web framework to consider is actix web

1 Like