|
1 | 1 | //! A general purpose library of common HTTP types
|
2 | 2 | //!
|
3 | 3 | //! This crate is a general purpose library for common types found when working
|
4 |
| -//! with the HTTP protocol. You'll find `Request` and `Response` types for |
| 4 | +//! with the HTTP protocol. You'll find [`Request`] and [`Response`] types for |
5 | 5 | //! working as either a client or a server as well as all of their components.
|
6 |
| -//! Notably you'll find `Uri` for what a `Request` is requesting, a `Method` |
7 |
| -//! for how it's being requested, a `StatusCode` for what sort of response came |
8 |
| -//! back, a `Version` for how this was communicated, and |
9 |
| -//! `HeaderName`/`HeaderValue` definitions to get grouped in a `HeaderMap` to |
| 6 | +//! Notably you'll find `Uri` for what a [`Request`] is requesting, a [`Method`] |
| 7 | +//! for how it's being requested, a [`StatusCode`] for what sort of response came |
| 8 | +//! back, a [`Version`] for how this was communicated, and |
| 9 | +//! [`HeaderName`][header::HeaderName]/[`HeaderValue`][header::HeaderName] definitions to get grouped in a [`HeaderMap`] to |
10 | 10 | //! work with request/response headers.
|
11 | 11 | //!
|
12 | 12 | //! You will notably *not* find an implementation of sending requests or
|
|
19 | 19 | //!
|
20 | 20 | //! ## Requests and Responses
|
21 | 21 | //!
|
22 |
| -//! Perhaps the main two types in this crate are the `Request` and `Response` |
23 |
| -//! types. A `Request` could either be constructed to get sent off as a client |
24 |
| -//! or it can also be received to generate a `Response` for a server. Similarly |
25 |
| -//! as a client a `Response` is what you get after sending a `Request`, whereas |
26 |
| -//! on a server you'll be manufacturing a `Response` to send back to the client. |
| 22 | +//! Perhaps the main two types in this crate are the [`Request`] and [`Response`] |
| 23 | +//! types. A [`Request`] could either be constructed to get sent off as a client |
| 24 | +//! or it can also be received to generate a [`Response`] for a server. Similarly |
| 25 | +//! as a client a [`Response`] is what you get after sending a [`Request`], whereas |
| 26 | +//! on a server you'll be manufacturing a [`Response`] to send back to the client. |
27 | 27 | //!
|
28 | 28 | //! Each type has a number of accessors for the component fields. For as a
|
29 | 29 | //! server you might want to inspect a requests URI to dispatch it:
|
|
45 | 45 | //! # fn not_found(_req: Request<()>) -> http::Result<Response<()>> { panic!() }
|
46 | 46 | //! ```
|
47 | 47 | //!
|
48 |
| -//! On a `Request` you'll also find accessors like `method` to return a |
49 |
| -//! `Method` and `headers` to inspect the various headers. A `Response` |
| 48 | +//! On a [`Request`] you'll also find accessors like [`method`][Request::method] to return a |
| 49 | +//! [`Method`] and [`headers`][Request::method] to inspect the various headers. A [`Response`] |
50 | 50 | //! has similar methods for headers, the status code, etc.
|
51 | 51 | //!
|
52 | 52 | //! In addition to getters, request/response types also have mutable accessors
|
|
64 | 64 | //! ```
|
65 | 65 | //!
|
66 | 66 | //! And finally, one of the most important aspects of requests/responses, the
|
67 |
| -//! body! The `Request` and `Response` types in this crate are *generic* in |
| 67 | +//! body! The [`Request`] and [`Response`] types in this crate are *generic* in |
68 | 68 | //! what their body is. This allows downstream libraries to use different
|
69 | 69 | //! representations such as `Request<Vec<u8>>`, `Response<impl Read>`,
|
70 | 70 | //! `Request<impl Stream<Item = Vec<u8>, Error = _>>`, or even
|
|
87 | 87 | //! Accept: text/html
|
88 | 88 | //! ```
|
89 | 89 | //!
|
90 |
| -//! Then `"Accept"` is a `HeaderName` while `"text/html"` is a `HeaderValue`. |
| 90 | +//! Then `"Accept"` is a [`HeaderName`][header::HeaderName] while `"text/html"` is a [`HeaderValue`][header::HeaderValue]. |
91 | 91 | //! Each of these is a dedicated type to allow for a number of interesting
|
92 | 92 | //! optimizations and to also encode the static guarantees of each type. For
|
93 |
| -//! example a `HeaderName` is always a valid `&str`, but a `HeaderValue` may |
| 93 | +//! example a [`HeaderName`][header::HeaderName] is always a valid `&str`, but a [`HeaderValue`] may |
94 | 94 | //! not be valid UTF-8.
|
95 | 95 | //!
|
96 | 96 | //! The most common header names are already defined for you as constant values
|
97 |
| -//! in the `header` module of this crate. For example: |
| 97 | +//! in the [`header`] module of this crate. For example: |
98 | 98 | //!
|
99 | 99 | //! ```
|
100 | 100 | //! use http::header::{self, HeaderName};
|
|
112 | 112 | //! assert_eq!(name, header::ACCEPT);
|
113 | 113 | //! ```
|
114 | 114 | //!
|
115 |
| -//! Header values can be created from string literals through the `from_static` |
| 115 | +//! Header values can be created from string literals through the [`from_static`][header::HeaderValue::from_static] |
116 | 116 | //! function:
|
117 | 117 | //!
|
118 | 118 | //! ```
|
|
133 | 133 | //!
|
134 | 134 | //! Most HTTP requests and responses tend to come with more than one header, so
|
135 | 135 | //! it's not too useful to just work with names and values only! This crate also
|
136 |
| -//! provides a `HeaderMap` type which is a specialized hash map for keys as |
137 |
| -//! `HeaderName` and generic values. This type, like header names, is optimized |
| 136 | +//! provides a [`HeaderMap`] type which is a specialized hash map for keys as |
| 137 | +//! [`HeaderName`][header::HeaderName] and generic values. This type, like header names, is optimized |
138 | 138 | //! for common usage but should continue to scale with your needs over time.
|
139 | 139 | //!
|
140 | 140 | //! # URIs
|
141 | 141 | //!
|
142 |
| -//! Each HTTP `Request` has an associated URI with it. This may just be a path |
| 142 | +//! Each HTTP [`Request`] has an associated URI with it. This may just be a path |
143 | 143 | //! like `/index.html` but it could also be an absolute URL such as
|
144 |
| -//! `https://www.rust-lang.org/index.html`. A `URI` has a number of accessors to |
| 144 | +//! `https://www.rust-lang.org/index.html`. A [`URI`][uri::Uri] has a number of accessors to |
145 | 145 | //! interpret it:
|
146 | 146 | //!
|
147 | 147 | //! ```
|
|
0 commit comments