Module hyper::server [] [src]

HTTP Server

A Server is created to listen on a port, parse HTTP requests, and hand them off to a Service.

There are two levels of APIs provide for constructing HTTP servers:

Server

The Server is main way to start listening for HTTP requests. It wraps a listener with a NewService, and then should be executed to start serving requests.

Example

extern crate hyper;

use hyper::{Body, Response, Server};
use hyper::service::service_fn_ok;

fn main() {
    // Construct our SocketAddr to listen on...
    let addr = ([127, 0, 0, 1], 3000).into();

    // And a NewService to handle each connection...
    let new_service = || {
        service_fn_ok(|_req| {
            Response::new(Body::from("Hello World"))
        })
    };

    // Then bind and serve...
    let server = Server::bind(&addr)
        .serve(new_service);

    // Finally, spawn `server` onto an Executor...
    hyper::rt::run(server.map_err(|e| {
        eprintln!("server error: {}", e);
    }));
}

Modules

conn

Lower-level Server connection API.

Structs

Builder

A builder for a Server.

Server

A listening HTTP server.