Merge pull request #473 from hyperium/docup

Docup
This commit is contained in:
Sean McArthur
2015-04-22 15:45:09 -07:00
3 changed files with 45 additions and 10 deletions

View File

@@ -5,18 +5,32 @@
//! The `Client` API is designed for most people to make HTTP requests. //! The `Client` API is designed for most people to make HTTP requests.
//! It utilizes the lower level `Request` API. //! It utilizes the lower level `Request` API.
//! //!
//! ```no_run //! ## GET
//! use hyper::Client;
//! //!
//! ```no_run
//! # use hyper::Client;
//! let mut client = Client::new(); //! 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); //! assert_eq!(res.status, hyper::Ok);
//! ``` //! ```
//! //!
//! The returned value from is a `Response`, which provides easy access //! The returned value is a `Response`, which provides easy access to
//! to the `status`, the `headers`, and the response body via the `Writer` //! the `status`, the `headers`, and the response body via the `Read`
//! trait. //! 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::default::Default;
use std::io::{self, copy, Read}; use std::io::{self, copy, Read};
use std::iter::Extend; use std::iter::Extend;

View File

@@ -9,8 +9,9 @@
//! is a low-level typesafe abstraction over raw HTTP, providing an elegant //! is a low-level typesafe abstraction over raw HTTP, providing an elegant
//! layer over "stringly-typed" HTTP. //! layer over "stringly-typed" HTTP.
//! //!
//! Hyper offers both an HTTP/S client an HTTP server which can be used to drive //! Hyper offers both a [Client](client/index.html) and a
//! complex web applications written entirely in Rust. //! [Server](server/index.html) which can be used to drive complex web
//! applications written entirely in Rust.
//! //!
//! ## Internal Design //! ## Internal Design
//! //!
@@ -20,8 +21,8 @@
//! //!
//! ### Common Functionality //! ### Common Functionality
//! //!
//! Functionality and code shared between the Server and Client implementations can //! Functionality and code shared between the Server and Client implementations
//! be found in `src` directly - this includes `NetworkStream`s, `Method`s, //! can be found in `src` directly - this includes `NetworkStream`s, `Method`s,
//! `StatusCode`, and so on. //! `StatusCode`, and so on.
//! //!
//! #### Methods //! #### Methods
@@ -38,7 +39,8 @@
//! //!
//! #### Headers //! #### 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 //! 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 //! typesafe API for interacting with headers that does not rely on the use of

View File

@@ -1,4 +1,23 @@
//! HTTP Server //! 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::fmt;
use std::io::{ErrorKind, BufWriter, Write}; use std::io::{ErrorKind, BufWriter, Write};
use std::marker::PhantomData; use std::marker::PhantomData;