6 releases (breaking)

0.6.0 Dec 31, 2022
0.5.0 Jul 29, 2022
0.4.0 Mar 30, 2022
0.3.0 Dec 4, 2021
0.1.1 Sep 16, 2021

#1306 in Web programming

Download history 1489/week @ 2024-06-09 1294/week @ 2024-06-16 1449/week @ 2024-06-23 1104/week @ 2024-06-30 1155/week @ 2024-07-07 1797/week @ 2024-07-14 1989/week @ 2024-07-21 2110/week @ 2024-07-28 1610/week @ 2024-08-04 1455/week @ 2024-08-11 1859/week @ 2024-08-18 1437/week @ 2024-08-25 1443/week @ 2024-09-01 1775/week @ 2024-09-08 1747/week @ 2024-09-15 1320/week @ 2024-09-22

6,344 downloads per month
Used in 34 crates (10 directly)

MIT/Apache

215KB
4K SLoC

Workflow Status Maintenance

ipfs-api

Components

Name Documentation Crate
ipfs-api-prelude Docs Crate
ipfs-api-backend-actix Docs Crate
ipfs-api-backend-hyper Docs Crate
ipfs-api (deprecated) Docs Crate

Rust library for connecting to the IPFS HTTP API using Hyper/Actix.

Usage

Using Hyper

To use the Hyper backend, declare:

[dependencies]
ipfs-api-backend-hyper = "0.6"

You can specify either with-hyper-rustls or with-hyper-tls (mutually exclusive) feature for TLS support.

Using Actix

To use the Actix backend, declare:

[dependencies]
ipfs-api-backend-actix = "0.7"

Builder Pattern

With either the Hyper or Actix backend, you can specify the with-builder feature to enable a builder pattern to use when building requests.

Usage (DEPRECATED)

[dependencies]
ipfs-api = "0.17.0"

Feature Flags (DEPRECATED)

You can use actix-web as a backend instead of hyper.

[dependencies]
ipfs-api = { version = "0.17.0", features = ["with-actix"], default-features = false }

You also have the option of using rustls instead of native tls:

[dependencies]
ipfs-api = { version = "0.17.0", features = ["with-hyper-rustls"], default-features = false }

To enable the builder pattern (default) use the with-builder feature:

[dependencies]
ipfs-api = { version = "0.17.0", features = ["with-hyper-rustls", "with-builder"], default-features = false }

Examples

Writing a file to IPFS

With Hyper
use ipfs_api::{IpfsApi, IpfsClient};
use std::io::Cursor;

#[tokio::main]
async fn main() {
    let client = IpfsClient::default();
    let data = Cursor::new("Hello World!");

    match client.add(data).await {
        Ok(res) => println!("{}", res.hash),
        Err(e) => eprintln!("error adding file: {}", e)
    }
}
With Actix
use ipfs_api::{IpfsApi, IpfsClient};
use std::io::Cursor;

#[actix_rt::main]
async fn main() {
    let client = IpfsClient::default();
    let data = Cursor::new("Hello World!");

    match client.add(data).await {
        Ok(res) => println!("{}", res.hash),
        Err(e) => eprintln!("error adding file: {}", e)
    }
}

Reading a file from IPFS

With Hyper
use futures::TryStreamExt;
use ipfs_api::{IpfsApi, IpfsClient};
use std::io::{self, Write};

#[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
use futures::TryStreamExt;
use ipfs_api::{IpfsApi, IpfsClient};
use std::io::{self, Write};

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

There are also a bunch of examples included in the project, which I used for testing

For a list of examples, run:

$ cargo run --example

You can run any of the examples with cargo:

$ cargo run --example add_file

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~10–25MB
~393K SLoC