xrpc

Core library for XRPC communication 🦋

1. Guide 🌎

This library provides the easiest way to use XRPC communication supported by AT Protocol in Dart and Flutter apps.

1.1. Getting Started âš¡

1.1.1. Install Library

With Dart:

 dart pub add xrpc

Or With Flutter:

 flutter pub add xrpc

1.1.2. Import

import 'package:xrpc/xrpc.dart';

1.1.3. Implementation

import 'dart:convert';

import 'package:xrpc/xrpc.dart' as xrpc;

Future<void> main() async {
  final response = await xrpc.procedure<String>(
    xrpc.NSID.create('server.atproto.com', 'createSession'),
    body: {'identifier': 'HANDLE_OR_EMAIL', 'password': 'PASSWORD'},
  );

  final session = jsonDecode(response.data);

  final currentSession = await xrpc.query<String>(
    xrpc.NSID.create('server.atproto.com', 'getSession'),
    headers: {'Authorization': 'Bearer ${session['accessJwt']}'},
  );

  print(currentSession);
}

Pass a to converter to deserialize the response body into your own type instead of receiving it as a raw String.

Streaming (Subscriptions)

For event-stream endpoints (e.g. a firehose), use subscribe<T>. It returns an XRPCResponse<Subscription<T>> synchronously; the payload's stream emits frames until you close() it.

import 'package:xrpc/xrpc.dart' as xrpc;

Future<void> main() async {
  final response = xrpc.subscribe<String>(
    xrpc.NSID.create('sync.atproto.com', 'subscribeRepos'),
  );

  final subscription = response.data;
  final events = subscription.stream.listen(print);

  // ... later, stop listening and close the underlying WebSocket.
  await events.cancel();
  await subscription.close();
}

Libraries

http
xrpc