From bf53ecbf41d7c93f417f8f11c2affdda234e15b7 Mon Sep 17 00:00:00 2001 From: Ferris Tseng Date: Sun, 3 Dec 2017 16:32:03 -0500 Subject: finish up adding documentation --- ipfs-api/src/lib.rs | 67 ++++++++++++++++++++++++++++++++++++++++++++ ipfs-api/src/response/mod.rs | 2 ++ 2 files changed, 69 insertions(+) (limited to 'ipfs-api') 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; diff --git a/ipfs-api/src/response/mod.rs b/ipfs-api/src/response/mod.rs index 2f3872f..e42c067 100644 --- a/ipfs-api/src/response/mod.rs +++ b/ipfs-api/src/response/mod.rs @@ -6,6 +6,8 @@ // copied, modified, or distributed except according to those terms. // +//! This module contains structures returned by the IPFS API. + pub use self::add::*; pub use self::bitswap::*; pub use self::block::*; -- cgit v1.2.3