7 releases (4 breaking)
0.5.0 | Jan 17, 2023 |
---|---|
0.4.2 | Jan 16, 2023 |
0.3.0 | Nov 11, 2022 |
0.2.0 | Oct 25, 2022 |
0.1.0 | Oct 11, 2022 |
#4 in #gemtext
32KB
497 lines
Leda
A crate that implements the client logic for several small internet protocols. Currently only supports gemini but with plans to support other protocols in the future.
Get started
This is a minimal example to show what using this library is like. It will grab the gemini homepage and print it's contents both in the plain gemtext format and as html.
You can run this example by running cargo run --example readme
.
use leda::gemini::{self, gemtext::Gemtext};
use std::time::Duration;
fn main() {
let url = String::from("gemini://gemini.circumlunar.space/");
let mut client = gemini::Client::with_timeout(Some(Duration::from_secs(5)))
.expect("Failed to create gemini client");
let response = client.request(url).expect("Failed to retrieve gemini page");
// Check that the server responded successfully with a gemtext document
let body = if let gemini::header::StatusCode::Success = response.header.status {
if !response.header.meta.starts_with("text/gemini") {
panic!("The server didn't respond with a gemtext document when we expected it to");
}
response.body.as_ref().unwrap()
} else {
// you can handle differents errors, redirects, and input requests as you see fit from
// here on!
panic!("Page requested didn't return a body!");
};
let body = std::str::from_utf8(&body).expect("Failed to parse body as utf8");
assert!(Gemtext::new(body).is_ok());
println!("raw body: \n{}\n", body);
}
Dependencies
~9–21MB
~395K SLoC