3 releases (breaking)

0.3.0 Sep 11, 2022
0.2.0 Sep 6, 2022
0.1.0 Aug 29, 2022

#421 in HTTP client

MIT license

25KB
471 lines

eiga

CI crates.io docs.rs license

eiga is a WIP TMDB API client.

eiga is usable, but it doesn't cover much of the TMDB API yet.

Usage

Add eiga as a dependency in your Cargo.toml:

[dependencies]
eiga = "0.3.0"

Example

This example shows how to get details about a movie. You can find other examples in the examples folder.

use std::env;
use std::error::Error;

use serde::Deserialize;

use eiga::{movie, Client, Tmdb};

// eiga doesn't provide types for endpoint responses. Instead, users provide
// their own structs to deserialize into.
#[derive(Deserialize)]
struct MovieDetails {
    release_date: String,
    title: String,
}

fn main() -> Result<(), Box<dyn Error>> {
    // Create a TMDB client by providing an API access token. Here, the token
    // is stored in the TMDB_TOKEN environment variable.
    let token = env::var("TMDB_TOKEN")?;
    let tmdb = Tmdb::new(token);

    // Build an endpoint to get details about "Tokyo Drifter" (1966). Each
    // endpoint has setter methods for optional query string parameters.
    let tokyo_drifter_id = 45706;
    let movie_details_endpoint =
        movie::Details::new(tokyo_drifter_id).language("en-US");

    // Send the request! Type annotations are required because `send` can
    // deserialize the response to any type that implements `Deserialize`.
    let movie_details: MovieDetails = tmdb.send(&movie_details_endpoint)?;

    assert_eq!(movie_details.title, "Tokyo Drifter");
    assert_eq!(movie_details.release_date, "1966-04-10");

    Ok(())
}

Acknowledgements

  • The design of eiga is mostly based on the design of the gitlab crate. There's a nice writeup on its design here.

Dependencies

~3.5–5MB
~92K SLoC