atproto-http

Native HTTP transport for marianoguerra/atproto, over moonbitlang/async. Implements @xrpc.Transport; native target only.

atproto
bluesky
xrpc
http
transport
moon add marianoguerra/atproto-http@0.1.0
Download zip
Version
0.1.0
License
Apache-2.0
Last updated
4 days ago
Downloads
7
README

#marianoguerra/atproto-http

The native HTTP transport for marianoguerra/atproto, over moonbitlang/async.

moon add marianoguerra/atproto moon add marianoguerra/atproto-http

import {
"marianoguerra/atproto-http/transport",
"marianoguerra/atproto/client",
}

let client = @client.Client::new(@transport.HttpTransport::new())
client.login(identifier="alice.bsky.social", password=app_password) |> ignore
let feed = client.feed_get_timeline(limit=30)

HttpTransport::new takes an optional description, used only in error messages — a transport that cannot say where it was pointed makes a connection failure much harder to place. It also takes trust, for a self-signed development PDS, and proxy.

Native only. That is not a limitation being apologised for; it is the reason the library it serves builds on wasm, wasm-gc, js and native.

#Why this is a separate module

In MoonBit the module is the unit of publication and of dependencies, so an import applies to every package in it. Putting this file in marianoguerra/atproto would put an async runtime in the dependency graph of someone who only wants to build and validate records on wasm-gc. So the library depends on nothing outside moonbitlang/core; this module is opt-in.

The two are released together, and this one pins the library at an exact version.

#You may not need it

@xrpc.Transport is a two-method trait, and implementing it over whatever HTTP client your host already has is a dozen lines:

pub impl @xrpc.Transport for MyTransport with fn send(self, request) {
// Send request.body to request.url with request.headers, then answer:
{ status: ..., headers: ..., body: ... }
}

Three rules the library relies on, each documented in this module's source at the point it obeys them:

  • Lower-case the response header names. @xrpc.HttpResponse makes that a contract on the implementor, and the error taxonomy reads retry-after, ratelimit-reset and content-type through it — so forwarding Retry-After unchanged silently disables rate-limit backoff.
  • Do not forward content-length. Most HTTP clients compute their own, and sending both risks two conflicting headers on the wire.
  • Do not let your client's errors escape. Translate them, or a caller's catch sees a type from a library it never imported.

The body must be read as bytes, not text: getBlob and getRepo return images and CAR files, and decoding those as UTF-8 corrupts them.

For tests, @atproto/testing's FakeTransport answers from a scripted list and records what went out. No socket, every backend.

#Licence

Apache-2.0, the same as the library. See LICENSE.