Docs.rs
  • ipfs-api-0.14.0
    • ipfs-api 0.14.0
    • Docs.rs crate page
    • MIT OR Apache-2.0
    • Links
    • Repository
    • crates.io
    • Source
    • Owners
    • ferristseng
    • Dependencies
      • ipfs-api-backend-actix ^0.4 normal
      • ipfs-api-backend-hyper ^0.3 normal
      • ipfs-api-prelude ^0.3 normal
      • actix-rt ^2.5 dev
      • futures ^0.3 dev
      • tokio ^1 dev
    • Versions
    • 100% of the crate is documented
  • Go to latest version
  • Platform
    • i686-pc-windows-msvc
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-pc-windows-msvc
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation
☰
logo

Crate ipfs_api

Version 0.14.0

See all ipfs_api's items

  • Modules
  • Structs
  • Enums
  • Traits

Modules

  • request
  • response

Structs

  • ApiError
  • BackendWithGlobalOptions
  • Form
  • GlobalOptions
  • IpfsClient

Enums

  • Error
  • KeyType
  • Logger
  • LoggingLevel
  • ObjectTemplate

Traits

  • IpfsApi
  • TryFromUri
Change settings

Crate ipfs_api[−][src]

Expand description

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.3"

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.4"

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.14.0"

Feature Flags (DEPRECATED)

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

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

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

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

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

[dependencies]
ipfs-api = { version = "0.14.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

Modules

request
response

This module contains structures returned by the IPFS API.

Structs

ApiError
BackendWithGlobalOptions

A wrapper for Backend / IpfsApi that adds global options

Form

Implements the multipart/form-data media type as described by RFC 7578.

GlobalOptions

Options valid on any IPFS Api request

IpfsClient

Enums

Error
KeyType
Logger
LoggingLevel
ObjectTemplate

Traits

IpfsApi
TryFromUri

Loading search results...