From 8198f41ec0e2c1351c227a713bcb90ed4a45a260 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 22 Apr 2015 12:27:33 -0700 Subject: [PATCH 1/3] docs(lib): add links to main modules --- src/lib.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 24392bafaf..8b122d17bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,8 +9,9 @@ //! is a low-level typesafe abstraction over raw HTTP, providing an elegant //! layer over "stringly-typed" HTTP. //! -//! Hyper offers both an HTTP/S client an HTTP server which can be used to drive -//! complex web applications written entirely in Rust. +//! Hyper offers both a [Client](client/index.html) and a +//! [Server](server/index.html) which can be used to drive complex web +//! applications written entirely in Rust. //! //! ## Internal Design //! @@ -20,8 +21,8 @@ //! //! ### Common Functionality //! -//! Functionality and code shared between the Server and Client implementations can -//! be found in `src` directly - this includes `NetworkStream`s, `Method`s, +//! Functionality and code shared between the Server and Client implementations +//! can be found in `src` directly - this includes `NetworkStream`s, `Method`s, //! `StatusCode`, and so on. //! //! #### Methods @@ -38,7 +39,8 @@ //! //! #### Headers //! -//! Hyper's header representation is likely the most complex API exposed by Hyper. +//! Hyper's [header](header/index.html) representation is likely the most +//! complex API exposed by Hyper. //! //! Hyper's headers are an abstraction over an internal `HashMap` and provides a //! typesafe API for interacting with headers that does not rely on the use of From f9ea2dd5942c38b89600b0c3e058851858291e5c Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 22 Apr 2015 12:27:50 -0700 Subject: [PATCH 2/3] docs(server): add basic usage example --- src/server/mod.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/server/mod.rs b/src/server/mod.rs index c69392ba40..5574a5edc6 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -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; From 48a010ffd7bcca4ef290d17c54a11b10a3ed5897 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Wed, 22 Apr 2015 12:28:19 -0700 Subject: [PATCH 3/3] docs(client): add improved usage examples --- src/client/mod.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/client/mod.rs b/src/client/mod.rs index b4d46a38a4..4c12dc08b7 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -5,18 +5,32 @@ //! The `Client` API is designed for most people to make HTTP requests. //! It utilizes the lower level `Request` API. //! -//! ```no_run -//! use hyper::Client; +//! ## GET //! +//! ```no_run +//! # use hyper::Client; //! let mut client = Client::new(); //! -//! let mut res = client.get("http://example.domain").send().unwrap(); +//! let res = client.get("http://example.domain").send().unwrap(); //! assert_eq!(res.status, hyper::Ok); //! ``` //! -//! The returned value from is a `Response`, which provides easy access -//! to the `status`, the `headers`, and the response body via the `Writer` +//! The returned value is a `Response`, which provides easy access to +//! the `status`, the `headers`, and the response body via the `Read` //! trait. +//! +//! ## POST +//! +//! ```no_run +//! # use hyper::Client; +//! let mut client = Client::new(); +//! +//! let res = client.post("http://exmaple.domain") +//! .body("foo=bar") +//! .send() +//! .unwrap(); +//! assert_eq!(res.status, hyper::Ok); +//! ``` use std::default::Default; use std::io::{self, copy, Read}; use std::iter::Extend;