docs(server): add basic usage example

This commit is contained in:
Sean McArthur
2015-04-22 12:27:50 -07:00
parent 8198f41ec0
commit f9ea2dd594

View File

@@ -1,4 +1,23 @@
//! HTTP Server
//!
//! # Example
//!
//! ```no_run
//! use hyper::server::{Server, Request, Response};
//! use hyper::status::StatusCode;
//! use hyper::uri::RequestUri;
//!
//! let server = Server::http(|req: Request, mut res: Response| {
//! *res.status_mut() = match (req.method, req.uri) {
//! (hyper::Get, RequestUri::AbsolutePath(ref path)) if path == "/" => {
//! StatusCode::Ok
//! },
//! (hyper::Get, _) => StatusCode::NotFound,
//! _ => StatusCode::MethodNotAllowed
//! };
//!
//! res.start().unwrap().end().unwrap();
//! }).listen("0.0.0.0:8080").unwrap();
use std::fmt;
use std::io::{ErrorKind, BufWriter, Write};
use std::marker::PhantomData;