3 releases

0.1.2 Mar 6, 2024
0.1.1 Jan 19, 2024
0.1.0 Sep 5, 2023

#1286 in Web programming

Download history 1/week @ 2024-01-15 8/week @ 2024-02-19 22/week @ 2024-02-26 135/week @ 2024-03-04 27/week @ 2024-03-11 57/week @ 2024-04-01

90 downloads per month

MIT/Apache

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–18MB
~258K SLoC