#federation #decentralization #resources #fetch #serve #fetching #acct

webfinger

A crate to help you fetch and serve WebFinger resources

8 releases (4 breaking)

0.5.1 Jun 12, 2022
0.5.0 Jul 31, 2019
0.4.1 May 11, 2019
0.4.0 Mar 17, 2019
0.1.0 Jun 18, 2018

#975 in Web programming

Download history 18/week @ 2024-02-22 19/week @ 2024-02-29 18/week @ 2024-03-07 30/week @ 2024-03-14 14/week @ 2024-03-21 36/week @ 2024-03-28 28/week @ 2024-04-04 28/week @ 2024-04-11 15/week @ 2024-04-18 19/week @ 2024-04-25 6/week @ 2024-05-02 8/week @ 2024-05-09 13/week @ 2024-05-16 15/week @ 2024-05-23 21/week @ 2024-05-30 11/week @ 2024-06-06

62 downloads per month

GPL-3.0 license

22KB
467 lines

WebFinger Crates.io Libraries.io dependency status for GitHub repo Codecov Build Status

A crate to help you fetch and serve WebFinger resources.

Examples

Fetching a resource:

use webfinger::resolve;

fn main() {
    let res = resolve("acct:test@example.org", true).expect("Error while fetching resource");

    println!("Places to get more informations about {}:", res.subject);
    for link in res.links.into_iter() {
        println!("- {}", link.href);
    }
}

Serving resources:

use webfinger::Resolver;

pub struct MyResolver;

impl Resolver<DatabaseConnection> for MyResolver {
    fn instance_domain<'a>() -> &'a str {
        "instance.tld"
    }

    fn find(acct: String, db: DatabaseConnection) -> Result<Webfinger, ResolverError> {
        if let Some(user) = db.find_user_by_name(acct) {
            Ok(Webfinger {
                subject: acct.clone(),
                aliases: vec![acct.clone()],
                links: vec![
                    Link {
                        rel: "http://webfinger.net/rel/profile-page".to_string(),
                        mime_type: None,
                        href: user.profile_url()
                    }
                ]
            })
        } else {
            Err(ResolverError::NotFound)
        }
    }
}

fn main() {
    // Start a web server and map /.well-known/webfinger to a function calling MyResolver::endpoint
}

Dependencies

~4–19MB
~230K SLoC