diff options
author | Ferris Tseng <ferristseng@fastmail.fm> | 2019-02-13 21:51:57 -0500 |
---|---|---|
committer | Ferris Tseng <ferristseng@fastmail.fm> | 2019-02-13 21:51:57 -0500 |
commit | 0cd34b196863325132e54bc8f36b196659baeb17 (patch) | |
tree | afed8e2c10d7fdfa29d7f79191ddffbef6cdef26 /README.md | |
parent | de3588c7c369ea4f4cca66f89c12511d1170e5f5 (diff) |
formatting; docs update; version increment; small refactors
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 87 |
1 files changed, 84 insertions, 3 deletions
@@ -10,12 +10,21 @@ Rust library for connecting to the IPFS HTTP API using tokio. ```toml [dependencies] -ipfs-api = "0.5.0-alpha2" +ipfs-api = "0.5.1" +``` + +You can use `actix-web` as a backend instead of `hyper`. + +```toml +[dependencies] +ipfs-api = { version = "0.5.1", features = ["actix"], default-features = false } ``` ### Examples -Write a file to IPFS: +#### Writing a file to IPFS + +##### With Hyper ```rust # @@ -36,7 +45,35 @@ let req = client hyper::rt::run(req); ``` -Read a file from IPFS: +##### With Actix + +```rust +# +use futures::future::Future; +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_web::actix::run(|| { + req.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) +}); +``` + +#### Reading a file from IPFS + +##### With Hyper ```rust # @@ -60,15 +97,59 @@ let req = client hyper::rt::run(req); ``` +##### With Actix + +```rust +# +use futures::{Future, Stream}; +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_web::actix::run(|| { + req.then(|_| { + actix_web::actix::System::current().stop(); + Ok(()) + }) +}); +``` + +#### Additional Examples + There are also a bunch of examples included in the project, which I used for testing +For a list of examples, run: + +```sh +$ 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 +``` + + ## License Licensed under either of |