pub struct WebFingerResponse {
pub subject: String,
pub aliases: Option<Vec<String>>,
pub properties: Option<HashMap<String, String>>,
pub links: Vec<Link>,
}
Expand description
A WebFinger response.
This represents the response portion of a WebFinger query that is returned by a WebFinger server.
See RFC 7033 Section 4.4 for more information.
§Examples
use webfinger_rs::{Link, WebFingerResponse};
let avatar = Link::builder("http://webfinger.net/rel/avatar")
.href("https://example.com/avatar.png")
.build();
let profile = Link::builder("http://webfinger.net/rel/profile-page")
.href("https://example.com/profile/carol")
.build();
let response = WebFingerResponse::builder("acct:carol@example.com")
.alias("https://example.com/profile/carol")
.property("https://example.com/ns/role", "developer")
.link(avatar)
.link(profile)
.build();
Response
can be used as a response in Axum handlers as it implements
axum::response::IntoResponse
.
use axum::response::IntoResponse;
use webfinger_rs::{Link, WebFingerRequest, WebFingerResponse};
async fn handler(request: WebFingerRequest) -> WebFingerResponse {
// ... handle the request ...
WebFingerResponse::builder("acct:carol@example.com")
.alias("https://example.com/profile/carol")
.property("https://example.com/ns/role", "developer")
.link(
Link::builder("http://webfinger.net/rel/avatar")
.href("https://example.com/avatar.png"),
)
.build()
}
Fields§
§subject: String
The subject of the response.
This is the URI of the resource that the response is about.
Defined in RFC 7033 Section 4.4.1
aliases: Option<Vec<String>>
The aliases of the response.
Defined in RFC 7033 Section 4.4.2
properties: Option<HashMap<String, String>>
The properties of the response.
Defined in RFC 7033 Section 4.4.3
links: Vec<Link>
The links of the response.
Defined in RFC 7033 Section 4.4.4
Implementations§
Source§impl WebFingerResponse
impl WebFingerResponse
Sourcepub async fn try_from_reqwest(
response: Response,
) -> Result<WebFingerResponse, Error>
Available on crate feature reqwest
only.
pub async fn try_from_reqwest( response: Response, ) -> Result<WebFingerResponse, Error>
reqwest
only.Converts a reqwest response into a WebFinger response.
Source§impl Response
impl Response
Sourcepub fn builder<S: Into<String>>(subject: S) -> Builder
pub fn builder<S: Into<String>>(subject: S) -> Builder
Create a new [WebFingerBuilder
] with the given subject.
§Examples
use webfinger_rs::{Link, WebFingerResponse};
let avatar =
Link::builder("http://webfinger.net/rel/avatar").href("https://example.com/avatar.png");
let response = WebFingerResponse::builder("acct:carol@example.com")
.alias("https://example.com/profile/carol")
.property("https://example.com/ns/role", "developer")
.link(avatar)
.build();
Examples found in repository?
47async fn webfinger(request: WebFingerRequest) -> actix_web::Result<WebFingerResponse> {
48 info!("fetching webfinger resource: {:?}", request);
49 let subject = request.resource.to_string();
50 if subject != SUBJECT {
51 let message = format!("{subject} does not exist");
52 return Err(actix_web::error::ErrorNotFound(message))?;
53 }
54 let rel = Rel::new("http://webfinger.net/rel/profile-page");
55 let response = if request.rels.is_empty() || request.rels.contains(&rel) {
56 let link = Link::builder(rel).href(format!("https://example.com/profile/{subject}"));
57 WebFingerResponse::builder(subject).link(link).build()
58 } else {
59 WebFingerResponse::builder(subject).build()
60 };
61 Ok(response)
62}
More examples
47async fn webfinger(request: WebFingerRequest) -> axum::response::Result<WebFingerResponse> {
48 info!("fetching webfinger resource: {:?}", request);
49 let subject = request.resource.to_string();
50 if subject != SUBJECT {
51 let message = format!("{subject} does not exist");
52 return Err((StatusCode::NOT_FOUND, message).into());
53 }
54 let rel = Rel::new("http://webfinger.net/rel/profile-page");
55 let response = if request.rels.is_empty() || request.rels.contains(&rel) {
56 let link = Link::builder(rel).href(format!("https://example.com/profile/{subject}"));
57 WebFingerResponse::builder(subject).link(link).build()
58 } else {
59 WebFingerResponse::builder(subject).build()
60 };
61 Ok(response)
62}
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Response
impl<'de> Deserialize<'de> for Response
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl IntoResponse for WebFingerResponse
Available on crate feature axum
only.
impl IntoResponse for WebFingerResponse
axum
only.Source§fn into_response(self) -> AxumResponse
fn into_response(self) -> AxumResponse
Converts a WebFinger response into an axum response.
This is used to convert a WebFingerResponse
into an axum response in an axum route
handler. The response will be serialized as JSON and the Content-Type
header will be set
to application/jrd+json
.
See the axum example for more information.
§Example
use axum::response::IntoResponse;
use webfinger_rs::{Link, WebFingerRequest, WebFingerResponse};
async fn handler(request: WebFingerRequest) -> impl IntoResponse {
// ... your code to handle the webfinger request ...
let subject = request.resource.to_string();
let link = Link::builder("http://webfinger.net/rel/profile-page")
.href(format!("https://example.com/profile/{subject}"));
WebFingerResponse::builder(subject).link(link).build()
}
Source§impl Responder for WebFingerResponse
Available on crate feature actix
only.
impl Responder for WebFingerResponse
actix
only.type Body = <Json<Response> as Responder>::Body
Source§fn respond_to(self, _request: &HttpRequest) -> HttpResponse<Self::Body>
fn respond_to(self, _request: &HttpRequest) -> HttpResponse<Self::Body>
HttpResponse
.Source§impl TryFrom<Response> for WebFingerResponse
Available on crate feature reqwest
only.
impl TryFrom<Response> for WebFingerResponse
reqwest
only.