AT-URIs with DIDs are not "URLs". Can they be parsed using exiting libraries in popular programming langauges?
Typescript implementation (@atproto/uri
) is implemented "from scratch".
Assuming that the "URL" class in the formal web platform does not work.
The popular url-parse
NPM package works:
var parse = require('url-parse');
console.log(parse('at://did:plc:24ybard66vv44zksje25o7dz/app.bsky.feed.post/3jwdwj2ctlk25', {}));
net/url
(stdlib) does not work.
github.com/fredbi/uri does not work:
package main
import (
"fmt"
"github.com/fredbi/uri"
)
func main() {
u, err := uri.Parse("at://did:plc:24ybard66vv44zksje25o7dz/app.bsky.feed.post/3jwdwj2ctlk25")
if err != nil {
fmt.Printf("Invalid URI: %v", err)
} else {
fmt.Printf("%s", u.Authority())
}
}
// Invalid URI: invalid port in URI
url
and http
are the most popular crates.
use url;
fn main() {
println!("{:?}", url::Url::parse("at://did:plc:24ybard66vv44zksje25o7dz/app.bsky.feed.post/3jwdwj2ctlk25"))
}
// Err(InvalidPort)
use http;
fn main() {
println!("{:?}", http::uri::Uri::from_static("at://did:plc:24ybard66vv44zksje25o7dz/app.bsky.feed.post/3jwdwj2ctlk25"));
}
// thread 'main' panicked at 'static str is not valid URI: invalid authority'
uriparse
is the most popular alternative; it also does not work
use std::convert::TryFrom;
use uriparse;
fn main() {
println!("{:?}", uriparse::URI::try_from("at://did:plc:24ybard66vv44zksje25o7dz/app.bsky.feed.post/3jwdwj2ctlk
25"));
}
// Err(Authority(Host(InvalidIPv4OrRegisteredNameCharacter)))
urllib.parse
(stdlib) works fine; DID comes back in "netloc" section. tested
with python3.11
from urllib.parse import urlparse
aturi = "at://did:plc:24ybard66vv44zksje25o7dz/app.bsky.feed.post/3jwdwj2ctlk25
urlparse(aturi)