Skip to content
/ leda Public

A library implementation for Gemini protocol clients

Notifications You must be signed in to change notification settings

nahla-nee/leda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);
}

About

A library implementation for Gemini protocol clients

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages