summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerris Tseng <ferris@navapbc.com>2019-12-24 13:18:45 -0500
committerFerris Tseng <ferris@navapbc.com>2019-12-24 13:18:45 -0500
commitaf714812893d05d530e0e7168e9b1255f38632e7 (patch)
tree8c0bda97062899f291179ecfadc713543affb30c
parent3d61a5f9c12962a3b62ee851905afdf980368a22 (diff)
update documentation
-rw-r--r--Cargo.lock2
-rw-r--r--README.md126
-rw-r--r--ipfs-api/Cargo.toml2
-rw-r--r--ipfs-api/src/lib.rs12
4 files changed, 66 insertions, 76 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 0681c16..f47e91a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -941,7 +941,7 @@ dependencies = [
[[package]]
name = "ipfs-api"
-version = "0.5.2"
+version = "0.6.0"
dependencies = [
"actix-http 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"actix-multipart-rfc7578 0.3.0-rc (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/README.md b/README.md
index 4ce6302..e9dfd52 100644
--- a/README.md
+++ b/README.md
@@ -10,14 +10,14 @@ Rust library for connecting to the IPFS HTTP API using tokio.
```toml
[dependencies]
-ipfs-api = "0.5.2"
+ipfs-api = "0.6.0"
```
You can use `actix-web` as a backend instead of `hyper`.
```toml
[dependencies]
-ipfs-api = { version = "0.5.2", features = ["actix"], default-features = false }
+ipfs-api = { version = "0.6.0", features = ["actix"], default-features = false }
```
### Examples
@@ -27,43 +27,37 @@ ipfs-api = { version = "0.5.2", features = ["actix"], default-features = false }
##### With Hyper
```rust
-#
-use hyper::rt::Future;
use ipfs_api::IpfsClient;
use std::io::Cursor;
-let client = IpfsClient::default();
-let data = Cursor::new("Hello World!");
+#[tokio::main]
+async fn main() {
+ let client = IpfsClient::default();
+ let data = Cursor::new("Hello World!");
-let req = client
- .add(data)
- .map(|res| {
- println!("{}", res.hash);
- })
- .map_err(|e| eprintln!("{}", e));
-
-hyper::rt::run(req);
+ match client.add(data).await {
+ Ok(res) => println!("{}", res.hash),
+ Err(e) => eprintln!("error adding file: {}", e)
+ }
+}
```
##### With Actix
```rust
-#
-use futures::future::{Future, lazy};
use ipfs_api::IpfsClient;
use std::io::Cursor;
-let client = IpfsClient::default();
-let data = Cursor::new("Hello World!");
-
-let req = client
- .add(data)
- .map(|res| {
- println!("{}", res.hash);
- })
- .map_err(|e| eprintln!("{}", e));
+#[actix_rt::main]
+async fn main() {
+ let client = IpfsClient::default();
+ let data = Cursor::new("Hello World!");
-actix_rt::System::new("test").block_on(req);
+ match client.add(data).await {
+ Ok(res) => println!("{}", res.hash),
+ Err(e) => eprintln!("error adding file: {}", e)
+ }
+}
```
#### Reading a file from IPFS
@@ -71,49 +65,57 @@ actix_rt::System::new("test").block_on(req);
##### With Hyper
```rust
-#
-use futures::{Future, Stream};
+use futures::TryStreamExt;
use ipfs_api::IpfsClient;
use std::io::{self, Write};
-let client = IpfsClient::default();
-
-let req = client
- .get("/test/file.json")
- .concat2()
- .map(|res| {
- let out = io::stdout();
- let mut out = out.lock();
-
- out.write_all(&res).unwrap();
- })
- .map_err(|e| eprintln!("{}", e));
-
-hyper::rt::run(req);
+#[tokio::main]
+async fn main() {
+ let client = IpfsClient::default();
+
+ match client
+ .get("/test/file.json")
+ .map_ok(|chunk| chunk.to_vec())
+ .try_concat()
+ .await
+ {
+ Ok(res) => {
+ let out = io::stdout();
+ let mut out = out.lock();
+
+ out.write_all(&res).unwrap();
+ }
+ Err(e) => eprintln!("error getting file: {}", e)
+ }
+}
```
##### With Actix
```rust
-#
-use futures::{Future, lazy, Stream};
+use futures::TryStreamExt;
use ipfs_api::IpfsClient;
use std::io::{self, Write};
-let client = IpfsClient::default();
-
-let req = client
- .get("/test/file.json")
- .concat2()
- .map(|res| {
- let out = io::stdout();
- let mut out = out.lock();
-
- out.write_all(&res).unwrap();
- })
- .map_err(|e| eprintln!("{}", e));
-
-actix_rt::System::new("test").block_on(req);
+#[actix_rt::main]
+async fn main() {
+ let client = IpfsClient::default();
+
+ match client
+ .get("/test/file.json")
+ .map_ok(|chunk| chunk.to_vec())
+ .try_concat()
+ .await
+ {
+ Ok(res) => {
+ let out = io::stdout();
+ let mut out = out.lock();
+
+ out.write_all(&res).unwrap();
+ }
+ Err(e) => eprintln!("error getting file: {}", e)
+ }
+}
```
#### Additional Examples
@@ -130,13 +132,7 @@ $ cargo run --example
You can run any of the examples with cargo:
```sh
-$ cargo run -p ipfs-api --example add_file
-```
-
-To run an example with the `actix-web` backend, use:
-
-```sh
-$ cargo run -p ipfs-api --features actix --no-default-features --example add_file
+$ cargo run --example add_file
```
diff --git a/ipfs-api/Cargo.toml b/ipfs-api/Cargo.toml
index 64a7171..56e6c5f 100644
--- a/ipfs-api/Cargo.toml
+++ b/ipfs-api/Cargo.toml
@@ -7,7 +7,7 @@ documentation = "https://docs.rs/ipfs-api"
repository = "https://github.com/ferristseng/rust-ipfs-api"
keywords = ["ipfs"]
categories = ["filesystem", "web-programming"]
-version = "0.5.2"
+version = "0.6.0"
readme = "../README.md"
license = "MIT OR Apache-2.0"
diff --git a/ipfs-api/src/lib.rs b/ipfs-api/src/lib.rs
index 27cf2bf..bd1f8d0 100644
--- a/ipfs-api/src/lib.rs
+++ b/ipfs-api/src/lib.rs
@@ -14,14 +14,14 @@
//!
//! ```toml
//! [dependencies]
-//! ipfs-api = "0.5.2"
+//! ipfs-api = "0.6.0"
//! ```
//!
//! You can use `actix-web` as a backend instead of `hyper`.
//!
//! ```toml
//! [dependencies]
-//! ipfs-api = { version = "0.5.2", features = ["actix"], default-features = false }
+//! ipfs-api = { version = "0.6.0", features = ["actix"], default-features = false }
//! ```
//!
//! ## Examples
@@ -136,13 +136,7 @@
//! You can run any of the examples with cargo:
//!
//! ```sh
-//! $ cargo run -p ipfs-api --example add_file
-//! ```
-//!
-//! To run an example with the `actix-web` backend, use:
-//!
-//! ```sh
-//! $ cargo run -p ipfs-api --features actix --no-default-features --example add_file
+//! $ cargo run --example add_file
//! ```
//!