diff options
author | Ferris Tseng <ferristseng@fastmail.fm> | 2017-12-03 16:32:03 -0500 |
---|---|---|
committer | Ferris Tseng <ferristseng@fastmail.fm> | 2017-12-03 16:32:03 -0500 |
commit | bf53ecbf41d7c93f417f8f11c2affdda234e15b7 (patch) | |
tree | 56241358ec655870d639ced25801d4afe99cc5f0 /ipfs-api/src/lib.rs | |
parent | 96a3854ece8f61d71c440498745b7b0054757753 (diff) |
finish up adding documentation
Diffstat (limited to 'ipfs-api/src/lib.rs')
-rw-r--r-- | ipfs-api/src/lib.rs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/ipfs-api/src/lib.rs b/ipfs-api/src/lib.rs index e2770ac..78d0569 100644 --- a/ipfs-api/src/lib.rs +++ b/ipfs-api/src/lib.rs @@ -6,6 +6,73 @@ // copied, modified, or distributed except according to those terms. // +//! Rust library for connecting to the IPFS HTTP API using tokio. +//! +//! ## Usage +//! +//! ```toml +//! [dependencies] +//! ipfs-api = "0.4.0-alpha" +//! ``` +//! +//! ## Examples +//! +//! Write a file to IPFS: +//! +//! ```no_run +//! # extern crate ipfs_api; +//! # extern crate tokio_core; +//! # +//! use ipfs_api::IpfsClient; +//! use std::io::Cursor; +//! use tokio_core::reactor::Core; +//! +//! # fn main() { +//! let mut core = Core::new().unwrap(); +//! let client = IpfsClient::default(&core.handle()); +//! let data = Cursor::new("Hello World!"); +//! +//! let req = client.add(data); +//! let res = core.run(req).unwrap(); +//! +//! println!("{}", res.hash); +//! # } +//! ``` +//! +//! Read a file from IPFS: +//! +//! ```no_run +//! # extern crate futures; +//! # extern crate ipfs_api; +//! # extern crate tokio_core; +//! # +//! use futures::stream::Stream; +//! use ipfs_api::IpfsClient; +//! use std::io::{self, Write}; +//! use tokio_core::reactor::Core; +//! +//! # fn main() { +//! let mut core = Core::new().unwrap(); +//! let client = IpfsClient::default(&core.handle()); +//! +//! let req = client.get("/test/file.json").concat2(); +//! let res = core.run(req).unwrap(); +//! let out = io::stdout(); +//! let mut out = out.lock(); +//! +//! out.write_all(&res).unwrap(); +//! # } +//! ``` +//! +//! There are also a bunch of examples included in the project, which +//! I used for testing +//! +//! You can run any of the examples with cargo: +//! +//! ```sh +//! $ cargo run -p ipfs-api --example add_file +//! ``` + extern crate bytes; #[macro_use] extern crate error_chain; |