izihawa_hyper_multipart/lib.rs
1// Copyright 2017 rust-multipart-rfc7578 Developers
2//
3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5// http://opensource.org/licenses/MIT>, at your option. This file may not be
6// copied, modified, or distributed except according to those terms.
7//
8
9//! This crate contains an implementation of the multipart/form-data media
10//! type described in [RFC 7578](https://tools.ietf.org/html/rfc7578) for
11//! [hyper](https://hyper.rs/).
12//!
13//! ## Usage
14//!
15//! Declare the dependency:
16//!
17//! ```toml
18//! [dependencies]
19//! izihawa-hyper-multipart = "1.0"
20//! ```
21//!
22//! Import the crate:
23//!
24//! ```rust
25//! extern crate izihawa_hyper_multipart as multipart;
26//! ```
27//!
28//! ## Example:
29//!
30//! With a custom client:
31//!
32//! ```rust
33//! extern crate izihawa_hyper_multipart as hyper_multipart;
34//!
35//! use hyper::{Client, Request};
36//! use hyper_multipart::client::{self, multipart};
37//!
38//! #[tokio::main]
39//! async fn main() {
40//! let client = Client::builder().build_http();
41//! let mut form = multipart::Form::default();
42//!
43//! form.add_text("test", "Hello World");
44//!
45//! let mut req_builder = Request::get("http://localhost/upload");
46//! let req = form.set_body::<multipart::Body>(req_builder).unwrap();
47//!
48//! if let Ok(_) = client.request(req).await {
49//! println!("done...");
50//! } else {
51//! eprintln!("an error occurred");
52//! }
53//! }
54//! ```
55//!
56//! With a default client:
57//!
58//! ```rust
59//! extern crate izihawa_hyper_multipart as hyper_multipart;
60//!
61//! use hyper::{
62//! Client, Request,
63//! };
64//! use hyper_multipart::client::{self, multipart};
65//!
66//! #[tokio::main]
67//! async fn main() {
68//! let client = Client::new();
69//! let mut form = multipart::Form::default();
70//!
71//! form.add_text("test", "Hello World");
72//!
73//! let mut req_builder = Request::get("http://localhost/upload");
74//! let req = form.set_body_convert::<hyper::Body, multipart::Body>(req_builder)
75//! .unwrap();
76//!
77//! if let Ok(_) = client.request(req).await {
78//! println!("done...");
79//! } else {
80//! eprintln!("an error occurred");
81//! }
82//! }
83//! ```
84//!
85
86#![allow(clippy::needless_doctest_main)]
87
88extern crate izihawa_common_multipart as common_multipart;
89
90mod body;
91
92pub mod client {
93 pub use common_multipart::client::Error;
94
95 pub mod multipart {
96 pub use crate::body::Body;
97 pub use common_multipart::client::multipart::{BoundaryGenerator, Form};
98 }
99}