4 releases

0.2.1 Mar 14, 2024
0.2.0 Feb 19, 2024
0.1.1 Feb 14, 2024
0.1.0 Feb 14, 2024

#1491 in Web programming

Download history 233/week @ 2024-02-14 56/week @ 2024-02-21 34/week @ 2024-02-28 3/week @ 2024-03-06 111/week @ 2024-03-13 12/week @ 2024-03-20 3/week @ 2024-03-27 7/week @ 2024-04-03 54/week @ 2024-04-10

77 downloads per month
Used in trakt-rs

MIT license

59KB
1.5K SLoC

trakt-rs

A Pure Rust Library for the Trakt.tv API

Crates.io Version docs.rs Crates.io License Rust codecov

Trakt.tv API Documentation: https://trakt.docs.apiary.io

Usage

This library does not provide a client for making HTTP(s) requests. That is left to the user. This enables the user to use any HTTP client they prefer (e.g. reqwest, hyper, isahc, etc.) with any TLS backend (e.g. native-tls, rustls, etc.) in a synchronous or asynchronous manner.

Instead, the library provides a set of request and response types that can be converted into the general purpose http::Request and http::Response types. The types fill out the entirety of the HTTP request, including the URL, headers, and body. However, the user may still modify the request before sending it.

The advantage of this approach is that the user has infinite flexibility in how they make requests. They can use any HTTP client, any TLS backend, and any request/response handling mechanism. Additionally, the user is free to make modifications to the request before sending it or the response after receiving it.

This also means this library has a smaller dependency tree, as it does not depend on runtime or HTTP client libraries.

Example

use trakt_rs::{Request, Response};

// Context required for all requests
let ctx = trakt_rs::Context {
    base_url: "https://api.trakt.tv",
    client_id: "client_id",
    oauth_token: None,
};

// Create a request and convert it into an HTTP request
let req = trakt_rs::api::movies::summary::Request {
    id: trakt_rs::smo::Id::Imdb("tt123456".into()),
};
let http_req: http::Request<Vec<u8>> = req.try_into_http_request(ctx).unwrap();

// Send the HTTP request using your preferred HTTP client
let response = http::Response::new(vec![]);

// Convert the HTTP response into a Trakt response
let trakt_response = trakt_rs::api::movies::summary::Response::try_from_http_response(response).unwrap();

println!("Movie: {:?}", trakt_response.0);

License: MIT

Dependencies

~3.5MB
~60K SLoC