| @@ -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; | ||||
|   | ||||
							
								
								
									
										12
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								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 | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user