4 releases
0.2.0 | Aug 31, 2024 |
---|---|
0.1.2 | Mar 6, 2024 |
0.1.1 | Jan 19, 2024 |
0.1.0 | Sep 5, 2023 |
#870 in Web programming
48KB
1K
SLoC
lotr-api-rs
This project is a Rust wrapper around the LOTR API.
Usage
There is more documentation available on the docs.rs page.
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);
}
This minimal example will print the information about the LOTR books available on the API.
License
This project is licensed under the MIT license and Apache License 2.0.
Contributing
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in lotr-api-rs
by you, shall be licensed as MIT and Apache 2.0,
without any additional terms or conditions.
Having said that, every contribution is welcome and I look forward to your PRs and issues.
lib.rs
:
lotr-api
This crate is a wrapper for the lotr-api. It provides a simple interface to make requests to the API.
Examples
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();
// ...
}
Features
Client
functions to get all items of a type .RequestBuilder
to build a request with filters, pagination and sorting, which allows the user full control over the request without having to deal with the url.
Dependencies
~4–15MB
~199K SLoC