ipfs-api 0.4.0-alpha.2

Implementation of an IPFS HTTP API client
Documentation

Rust library for connecting to the IPFS HTTP API using tokio.

Usage

[dependencies]
ipfs-api = "0.4.0-alpha.2"

Examples

Write a file to IPFS:

# 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:

# 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:

$ cargo run -p ipfs-api --example add_file