Expand description
Disclaimer: I made this lil library just for fun, with only a few features, so I wouldnt recommend using it. But if you use it anyway have fun :>.
There may be some parts where you need to know the R34 API, I probably forgot something 🤷♂️. So check out R34’s API
§Lil example
use std::fs;
use r34_api as r34;
use reqwest;
#[tokio::main]
async fn main() {
// First we make a new Api Url.
// We add the 'big_boobs' tag and a post limit of one so only one
// post will be returned and convert the ApiUrl type into a String.
let request_url = r34::ApiUrl::new().add_tag("big_boobs").set_limit(1).to_api_url();
// Next we send our request to R34's API.
let api_response = reqwest::get(request_url).await.unwrap();
// We then parse the json response and get a Vector with Post's.
let posts: Vec<r34::Post> = r34::R34JsonParser::default().from_api_response(api_response).unwrap();
// Here we get the filename and url of the post's file.
let post_file_url = &posts[0].file_url;
let post_file_name = &posts[0].image;
// Now we Download the file
let file_as_bytes = reqwest::get(post_file).await.unwrap().bytes().await.unwrap();
// Define its path
let path = format!("./{}", post_file_name);
// And save it.
fs::File::create(path).unwrap().write_all(&file_as_bytes).unwrap();
}
Structs§
- ApiUrl
- The ApiUrl Struct is used for easily generating API Urls.
- Post
- Post struct. Holds all information about a Post
- R34Json
Parser - A Parser for R34 API Json responses.