3个版本
0.1.2 | 2024年3月6日 |
---|---|
0.1.1 | 2024年1月19日 |
0.1.0 | 2023年9月5日 |
#20 in #rule
48KB
1K SLoC
lotr-api-rs
本项目是LOTR API的Rust包装器。
用法
有关更多文档,请参阅docs.rs页面。
use lotr_api::Client;
#[tokio::main]
async fn main() {
let client = Client::new("your-api-key");
let book = client.get_book("5cf5805fb53e011a64671582").await.unwrap();
println!("{:?}", book);
}
以下是最小示例,将打印API上可用的LOTR书籍信息。
许可证
本项目采用MIT许可证和Apache许可证2.0。
贡献
除非您明确表示,否则您有意提交以包含在lotr-api-rs
中的任何贡献,将按MIT和Apache 2.0许可,不附加任何额外条款或条件。
尽管如此,欢迎所有贡献,我期待您的PR和问题。
lib.rs
:
lotr-api
此crate是lotr-api的包装器。它提供了一个简单的接口来对API进行请求。
示例
use lotr_api::Client;
#[tokio::main]
async fn main() {
let client = Client::new("your_token".to_string());
let books = client.get_books().await.unwrap();
let characters = client.get_characters().await.unwrap();
}
use lotr_api::{Client, ItemType, RequestBuilder};
use lotr_api::filter::{Filter, Operator};
use lotr_api::sort::{Sort, SortOrder};
use lotr_api::attribute::{Attribute, BookAttribute};
#[tokio::main]
async fn main() {
let client = Client::new("your_token".to_string());
let request = RequestBuilder::new(ItemType::Book)
.filter(Filter::Match(
Attribute::Book(BookAttribute::Name),
Operator::Eq,
vec!["The Fellowship of the Ring".to_string()])
)
.sort(Sort::new(SortOrder::Ascending, Attribute::Book(BookAttribute::Name)))
.build()
.expect("Failed to build request");
let books = client.get(request).await.unwrap();
// ...
}
功能
Client
函数用于获取某类型所有项。RequestBuilder
用于构建带有过滤器、分页和排序的请求,允许用户完全控制请求,无需处理URL。
依赖项
~3–16MB
~228K SLoC