• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ferristseng/rust-ipfs-api: IPFS HTTP client in Rust

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

ferristseng/rust-ipfs-api

开源软件地址:

https://github.com/ferristseng/rust-ipfs-api

开源编程语言:

Rust 99.8%

开源软件介绍:

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

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

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

Feature Flags (DEPRECATED)

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

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

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

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

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

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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap