Crate jrd

Source
Expand description

§JRD

from Packetizer:

The JSON Resource Descriptor (JRD) is a simple JSON object that describes a “resource” on the Internet, where a “resource” is any entity on the Internet that is identified via a URI or IRI. For example, a person’s account URI (e.g., acct:bob@example.com) is a resource. So are all web URIs (e.g., https://www.packetizer.com/).

The JSON Resource Descriptor, originally introduced in RFC 6415 and based on the Extensible Resource Descriptor (XRD) format, was adopted for use in the WebFinger protocol, though its use is not restricted to WebFinger or RFC 6415.

This tiny crate provides a struct representation of JRDs, JsonResourceDescriptor, together with serde::Serialize and serde::Deserialize implementations.

All documentation is copied as-is from packetizer.com.

§usage

let jrd_string = r#"{
  "subject": "acct:paulej@packetizer.com",
  "properties": {
    "http://packetizer.com/ns/name": "Paul E. Jones"
  },
  "links": [
    {
      "rel": "http://webfinger.net/rel/profile-page",
      "href": "http://www.packetizer.com/people/paulej/"
    },
    {
      "rel": "http://packetizer.com/rel/blog",
      "type": "text/html",
      "href": "http://www.packetizer.com/people/paulej/blog/",
      "titles": {
        "en-us": "Paul E. Jones' Blog"
      }
    }
  ]
}"#;
 
let jrd_struct = jrd::JsonResourceDescriptor {
  subject: "acct:paulej@packetizer.com".into(),
  aliases: Vec::new(),
  properties: [("http://packetizer.com/ns/name".to_string(), "Paul E. Jones".to_string())].into(),
  expires: None,
  links: vec![
    jrd::JsonResourceDescriptorLink {
      rel: "http://webfinger.net/rel/profile-page".into(),
      href: Some("http://www.packetizer.com/people/paulej/".into()),
      link_type: None,
      titles: jrd::Map::default(),
      properties: jrd::Map::default(),
    },
    jrd::JsonResourceDescriptorLink {
      rel: "http://packetizer.com/rel/blog".into(),
      href: Some("http://www.packetizer.com/people/paulej/blog/".into()),
      link_type: Some("text/html".into()),
      titles: [("en-us".to_string(), "Paul E. Jones' Blog".to_string())].into(),
      properties: jrd::Map::default(),
    },
  ],
};

// deserialize
assert_eq!(serde_json::from_str::<jrd::JsonResourceDescriptor>(jrd_string).unwrap(), jrd_struct);

// serialize
assert_eq!(serde_json::to_string_pretty(&jrd_struct).unwrap(), jrd_string)

Structs§

JsonResourceDescriptor
The JSON Resource Descriptor (JRD) is a simple JSON object that describes a “resource” on the Internet, where a “resource” is any entity on the Internet that is identified via a URI or IRI.
JsonResourceDescriptorLink
Each of these link objects can have the following members:

Type Aliases§

Map
Time