Crate lotr_api

source ·
Expand description

§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.

Re-exports§

Modules§

  • Client definition. This is the main entry point for the library. It is used to make requests to the API. It is created with a token, which is used to authenticate the requests. You can get a token from https://the-one-api.dev/.
  • Definition of the Error type for the crate.
  • This module contains the data structures for the items that are returned by the API. It also holds the attribute::Attribute enum and its derivatives, that contain the attributes that represent the fields of the items ( they are used for filtering and sorting ).
  • This module contains the structs that are used to make a request to the API. Here we define the Request struct and the RequestBuilder struct, which are the center of the custom request system.