| 1 |
# HTTP |
| 2 |
|
| 3 |
A general purpose library of common HTTP types |
| 4 |
|
| 5 |
[](https://github.com/hyperium/http/actions?query=workflow%3ACI) |
| 6 |
[](https://crates.io/crates/http) |
| 7 |
[][dox] |
| 8 |
|
| 9 |
More information about this crate can be found in the [crate |
| 10 |
documentation][dox]. |
| 11 |
|
| 12 |
[dox]: https://docs.rs/http |
| 13 |
|
| 14 |
## Usage |
| 15 |
|
| 16 |
To use `http`, first add this to your `Cargo.toml`: |
| 17 |
|
| 18 |
```toml |
| 19 |
[dependencies] |
| 20 |
http = "0.2" |
| 21 |
``` |
| 22 |
|
| 23 |
Next, add this to your crate: |
| 24 |
|
| 25 |
```rust |
| 26 |
use http::{Request, Response}; |
| 27 |
|
| 28 |
fn main() { |
| 29 |
// ... |
| 30 |
} |
| 31 |
``` |
| 32 |
|
| 33 |
## Examples |
| 34 |
|
| 35 |
Create an HTTP request: |
| 36 |
|
| 37 |
```rust |
| 38 |
use http::Request; |
| 39 |
|
| 40 |
fn main() { |
| 41 |
let request = Request::builder() |
| 42 |
.uri("https://www.rust-lang.org/") |
| 43 |
.header("User-Agent", "awesome/1.0") |
| 44 |
.body(()) |
| 45 |
.unwrap(); |
| 46 |
} |
| 47 |
``` |
| 48 |
|
| 49 |
Create an HTTP response: |
| 50 |
|
| 51 |
```rust |
| 52 |
use http::{Response, StatusCode}; |
| 53 |
|
| 54 |
fn main() { |
| 55 |
let response = Response::builder() |
| 56 |
.status(StatusCode::MOVED_PERMANENTLY) |
| 57 |
.header("Location", "https://www.rust-lang.org/install.html") |
| 58 |
.body(()) |
| 59 |
.unwrap(); |
| 60 |
} |
| 61 |
``` |
| 62 |
|
| 63 |
# Supported Rust Versions |
| 64 |
|
| 65 |
This project follows the [Tokio MSRV][msrv] and is currently set to `1.49`. |
| 66 |
|
| 67 |
[msrv]: https://github.com/tokio-rs/tokio/#supported-rust-versions |
| 68 |
|
| 69 |
# License |
| 70 |
|
| 71 |
Licensed under either of |
| 72 |
|
| 73 |
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or https://apache.org/licenses/LICENSE-2.0) |
| 74 |
- MIT license ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT) |
| 75 |
|
| 76 |
# Contribution |
| 77 |
|
| 78 |
Unless you explicitly state otherwise, any contribution intentionally submitted |
| 79 |
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be |
| 80 |
dual licensed as above, without any additional terms or conditions. |