Current section
Files
Jump to
Current section
Files
README.md
# Possum ๐
[](https://hex.pm/packages/possum)
[](https://possum.hexdocs.pm/)
ATproto library for gleam. Helps you build HTTP requests that interact with
your [Personal Data Server](https://docs.bsky.app/docs/advanced-guides/atproto#achieving-scale).
The user is responsible for sending the request and decoding the response.
## AT Protocol
The AT Protocol stands for "Authenticated Transfer Protocol", the name is in
reference to the fact that all user-data is signed by the authoring users,
which makes it possible to broadcast the data through many services and
prove it's real without having to speak directly to the originating server.
## Example
```sh
gleam add possum gleam_http gleam_json
```
### Consulting your DID
```gleam
import gleam/http/request
import possum
// Resolve an atproto handle (hostname) to a DID.
//
// You can consult your identifier by sending a request directly to your PDS,
// or you can use projects like [Slingshot](https://slingshot.microcosm.blue)
// for easy access to cached data when resolving a handle.
request.new()
|> request.set_host("slingshot.microcosm.blue")
|> possum.resolve_handle("gleam.run")
// You also verify your DID without DNS by sending a request to `/.well-know/atproto-did`
// Your server can then respond with the DID value as plain text.
request.new()
|> possum.resolve_well_known_did("gleam.run")
// Use `did.parse` to turn strings into valid DID format
let assert Ok(did) = did.parse("did:plc:ewvi7nxzyoun6zhxrhs64oiz")
```
### Querying Public Data
```gleam
import gleam/http/request
import possum
let assert Ok(did) = did.parse("did:plc:ewvi7nxzyoun6zhxrhs64oiz")
// Reading public data from repositories.
// No authorization needed.
request.new()
|> request.set_host("personal.data-server.pds")
|> possum.list_records(
did,
collection: "sh.tangled.repo",
limit: option.Some(3),
cursor: option.None,
reverse: option.None,
)
```
### Authorized Requests
```gleam
import gleam/http/request
import possum
let assert Ok(did) = did.parse("did:plc:ewvi7nxzyoun6zhxrhs64oiz")
// App Passwords can be generated in your Bluesky settings,
// It allows authorized access to your PDS.
request.new()
|> request.set_host("personal.data-server.pds")
|> possum.create_session(
did,
app_password: "bsky-app-password",
allow_takendown: option.None,
auth_factor_token: option.None
)
// Include a authorization Header for requests that require authentication.
request.new()
|> request.set_host("personal.data-server.pds")
|> possum.authorized("access-token")
// Refreshing an authorized Session
request.new()
|> request.set_host("personal.data-server.pds")
|> possum.refresh_session("refresh-token")
```