A crate to help you fetch and serve WebFinger resources
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.7 KiB

2 years ago
2 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # WebFinger ![Crates.io](https://img.shields.io/crates/v/webfinger.svg) ![Libraries.io dependency status for GitHub repo](https://img.shields.io/librariesio/github/Plume-org/webfinger.svg) ![Codecov](https://img.shields.io/codecov/c/github/Plume-org/webfinger.svg) [![Build Status](https://travis-ci.org/Plume-org/webfinger.svg?branch=master)](https://travis-ci.org/Plume-org/webfinger)
  2. A crate to help you fetch and serve WebFinger resources.
  3. ## Examples
  4. Fetching a resource:
  5. ```rust
  6. use webfinger::resolve;
  7. fn main() {
  8. let res = resolve("acct:test@example.org", true).expect("Error while fetching resource");
  9. println!("Places to get more informations about {}:", res.subject);
  10. for link in res.links.into_iter() {
  11. println!("- {}", link.href);
  12. }
  13. }
  14. ```
  15. Serving resources:
  16. ```rust
  17. use webfinger::Resolver;
  18. pub struct MyResolver;
  19. impl Resolver<DatabaseConnection> for MyResolver {
  20. fn instance_domain<'a>() -> &'a str {
  21. "instance.tld"
  22. }
  23. fn find(acct: String, db: DatabaseConnection) -> Result<Webfinger, ResolverError> {
  24. if let Some(user) = db.find_user_by_name(acct) {
  25. Ok(Webfinger {
  26. subject: acct.clone(),
  27. aliases: vec![acct.clone()],
  28. links: vec![
  29. Link {
  30. rel: "http://webfinger.net/rel/profile-page".to_string(),
  31. mime_type: None,
  32. href: user.profile_url()
  33. }
  34. ]
  35. })
  36. } else {
  37. Err(ResolverError::NotFound)
  38. }
  39. }
  40. }
  41. fn main() {
  42. // Start a web server and map /.well-known/webfinger to a function calling MyResolver::endpoint
  43. }
  44. ```