···2020gleam add possum gleam_http gleam_json
2121```
22222323-### Consulting your DID
2323+### Decentralized Identifiers (DIDs)
24242525```gleam
2626import gleam/http/request
···3535|> request.set_host("slingshot.microcosm.blue")
3636|> possum.resolve_handle("gleam.run")
37373838-// You also verify your DID without DNS by sending a request to `/.well-know/atproto-did`
3939-// Your server can then respond with the DID value as plain text.
4040-request.new()
4141-|> possum.resolve_well_known_did("gleam.run")
4242-4338// Use `did.parse` to turn strings into valid DID format
4439let assert Ok(did) = did.parse("did:plc:ewvi7nxzyoun6zhxrhs64oiz")
4540```
46414747-### Querying Public Data
4242+### Building HTTP Requests
48434944```gleam
5045import gleam/http/request
5146import possum
4747+import possum/did
52485349let assert Ok(did) = did.parse("did:plc:ewvi7nxzyoun6zhxrhs64oiz")
5450
+8
gleam.toml
···44description = "๐ ATproto library for gleam"
55licences = ["Apache-2.0"]
66repository = { type = "tangled", user = "kacaii.dev", repo = "possum" }
77+78links = [
89 { title = "AT Protocol", href = "https://atproto.com/" },
910 { title = "Bluesky HTTP API Reference", href = "https://endpoints.bsky.app/" },
1011 { title = "Blogpost: A Social File System", href = "https://overreacted.io/a-social-filesystem/" },
1112]
1313+1414+[documentation]
1515+pages = [
1616+ { title = "Consulting your DID", path = "consulting-your-did.html", source = "./pages/consulting-your-did.md" },
1717+ { title = "Accessing your PDS", path = "accessing-your-pds.html", source = "./pages/accessing-your-pds.md" },
1818+]
1919+12201321[dependencies]
1422gleam_stdlib = ">= 1.0.0 and < 2.0.0"
+40
pages/accessing-your-pds.md
···11+# Accessing your PDS
22+33+PLC is a persistent global identifier system, stands for "Public Ledger of Credentials",
44+it's a persistent global identifier system, which allows accounts to retain relationships
55+while changing names or migrating between service providers
66+77+DID resolution can be as simple as:
88+99+```gleam
1010+import gleam/http/request
1111+import possum
1212+1313+let assert Ok(did) = did.parse("did:plc:z72i7hdynmk6r22z27h6tvur")
1414+1515+request.new()
1616+|> possum.get_plc_data(did)
1717+```
1818+1919+## Response
2020+2121+ ```json
2222+{
2323+ "did": "string",
2424+ "verificationMethods": {
2525+ "atproto": "string"
2626+ },
2727+ "rotationKeys": [
2828+ "string",
2929+ "string"
3030+ ],
3131+ "alsoKnownAs": [
3232+ "string"
3333+ ],
3434+ "services": {
3535+ "atproto_pds": {
3636+ "type": "string",
3737+ "endpoint": "string"
3838+ }
3939+}
4040+```
+41
pages/consulting-your-did.md
···11+# Consulting your DID
22+33+Users in AT Protocol have permanent decentralized identifiers (DIDs) for their accounts.
44+They also have a configurable domain name, which acts as a human-readable handle.
55+An example DID is `did:plc:ewvi7nxzyoun6zhxrhs64oiz.`
66+77+```gleam
88+// Use `did.parse` to turn strings into valid DID format
99+let assert Ok(did) = did.parse("did:plc:ewvi7nxzyoun6zhxrhs64oiz")
1010+```
1111+1212+## Handle Resolution
1313+1414+Handles have a limited role in atproto, and need to be resolved to a DID in almost
1515+all situations. Clients can rely on network services (eg, their PDS) to resolve
1616+handles for them, using the `com.atproto.identity.resolveHandle` endpoint, and
1717+don't usually need to implement resolution directly themselves.
1818+1919+```gleam
2020+// You can consult your identifier by sending a request directly to your PDS,
2121+// or you can use projects like [Slingshot](https://slingshot.microcosm.blue)
2222+// for easy access to cached data when resolving a handle.
2323+request.new()
2424+|> request.set_host("slingshot.microcosm.blue")
2525+|> possum.resolve_handle("gleam.run")
2626+```
2727+2828+## HTTPS well-known Method
2929+3030+A web server at the handle domain implements a special well-known endpoint at the
3131+path `/.well-known/atproto-did.` A valid HTTP response will have an HTTP success
3232+status (2xx) and include the DID as the HTTP body with no prefix or wrapper formatting.
3333+3434+```gleam
3535+// You also verify your DID without DNS by sending a request to `/.well-know/atproto-did`
3636+// Your server can then respond with the DID value as plain text.
3737+//
3838+// The response Content-Type header does not need to be strictly verified.
3939+request.new()
4040+|> possum.resolve_well_known_did("gleam.run")
4141+```
+6-1
src/possum.gleam
···5959/// import gleam/http/request
6060/// import possum
6161///
6262+/// let assert Ok(did) = did.parse("did:plc:z72i7hdynmk6r22z27h6tvur")
6363+///
6264/// let request =
6365/// request.new()
6464-/// |> possum.get_plc_data("did:plc:z72i7hdynmk6r22z27h6tvur")
6666+/// |> possum.get_plc_data(did)
6767+///
6868+/// // You can use this decoder to extract the server endpoint
6969+/// let decoder = decode.at(["services", "atproto_pds", "endpoint"], decode.string)
6570/// ```
6671///
6772/// ## Response
+3-3
src/possum/did.gleam
···2323}
24242525/// AT Protocol uses Decentralized Identifiers (DIDs) as persistent account
2626-/// identifiers. An example DID is did:plc:ewvi7nxzyoun6zhxrhs64oiz.
2626+/// identifiers. An example DID is `did:plc:ewvi7nxzyoun6zhxrhs64oiz`.
2727///
2828-/// Documentation: [DID](https://atproto.com/specs/did)
2828+/// Documentation: [Decentralized Identifiers](https://atproto.com/specs/did)
2929pub opaque type Did {
3030 Did(method: Method, identifier: String)
3131}
···87878888 case parse(value) {
8989 Ok(did) -> decode.success(did)
9090- Error(_) -> decode.failure(Did(Plc, "wibblewobble"), "DID")
9090+ Error(_) -> decode.failure(Did(method: Plc, identifier: "possum"), "DID")
9191 }
9292}
9393