Categorygithub.com/reiver/go-xrpc
modulepackage
0.0.0-20240905133829-2de40c4662d8
Repository: https://github.com/reiver/go-xrpc.git
Documentation: pkg.go.dev

# README

go-xrpc

Package xrpc provides an implementation of the XRPC protocol used by BlueSky and its AT-Protocol, for the Go programming language.

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-xrpc

GoDoc

Explanation

XRPC is a client-server protocol. This package implements both the client-side and the server-side of the protocol.

XRPC has 3 requests types:

  • executve (called procedure in the XRPC documentation),
  • query, and
  • subscribe.

This package provides functions for making each of these requests:

  • xrpc.Execute()
  • xrpc.Query()
  • xrpc.Subscribe()

(See examples to see how to use each.)

An XRPC URL needs to be passed to each of these functions. For example:

const url string = "xrpc://public.api.bsky.app/app.bsky.actor.getProfile?actor=reiver.bsky.social"

err := xrpc.Query(dst, url)

This package (introduces and) supports 2 types of XRPC URLs:

  • xrpc, and
  • xrpc-unencrypted.

For example:

  • xrpc://public.api.bsky.app/app.bsky.actor.getProfile?actor=reiver.bsky.social
  • xrpc-unencrypted://localhost/app.bsky.actor.getProfile?actor=reiver.bsky.social

Examples

Here is an example of making a 'query' XRPC request:

import "github.com/reiver/go-xrpc"

// ...

var response map[string]any = map[string]any{}

url := "xrpc://public.api.bsky.app/app.bsky.actor.getProfile?actor=reiver.bsky.social"

err := xrpc.Query(&response, url)

XRPC URL Resolution

This package introduces two URL schemes:

  • xrpc, and
  • xrpc-unencrypted.

For example:

  • xrpc://public.api.bsky.app/app.bsky.actor.getProfile?actor=reiver.bsky.social
  • xrpc-unencrypted://localhost/app.bsky.actor.getProfile?actor=reiver.bsky.social

Behind-the-scenes the scenes, these XRPC URL schemes are resolved to HTTPS, HTTP, WSS, and WS URLs.

MOST DEVELOPERS WHO ARE JUST MAKING XRPC CLIENT REQUESTS DO NOT HAVE TO WORRY ABOUT THE DETAILS OF THE RESOLUTION. IN THE SAME WAY THAT MOST DEVELOPERS DO NOT HAVE TO WORRY ABOUT HOW HTTP URLS ARE RESOLVED TO TCP.

How an XRPC URL gets resolved to an HTTPS, HTTP, WSS, or WS URL, depends on the XRPC request type.

Here are some examples:

XRPC URLXRPC Request TypeResolved URL
xrpc://example.com/app.cherry.fooBarexecutehttps://example.com/xrpc/app.cherry.fooBar
xrpc://example.com/app.cherry.fooBarqueryhttps://example.com/xrpc/app.cherry.fooBar
xrpc://example.com/app.cherry.fooBarsubscribewss://example.com/xrpc/app.cherry.fooBar
xrpc-unencrypted://localhost/link.banana.bazQuxexecutehttp://localhost/xrpc/link.banana.bazQux
xrpc-unencrypted://localhost/link.banana.bazQuxqueryhttp://localhost/xrpc/link.banana.bazQux
xrpc-unencrypted://localhost/link.banana.bazQuxsubscribews://localhost/xrpc/link.banana.bazQux

These 2 XRPC URLs are passed to the xrpc.Execute(), xrpc.Query(), and xrpc.Subscribe() functions.

Import

To import package xrpc use import code like the follownig:

import "github.com/reiver/go-xrpc"

Installation

To install package xrpc do the following:

GOPROXY=direct go get https://github.com/reiver/go-xrpc

Author

Package xrpc was written by Charles Iliya Krempeaux

# Functions

No description provided by the author
No description provided by the author
ConstructURL constructs an XRPC URL (i.e., "xrpc-unencrypted://...") from a 'host', an 'nsid', and a 'query'.
ConstructURL constructs an XRPC URL (i.e., "xrpc://...") from a 'host', an 'nsid', and a 'query'.
Execute makes an 'execute' XRPC request to the provided URL (passed in 'url'), putting the results into 'dst'.
MustParseURL is similar to [ParseURL] except that it panic()s if there is an error (rather than returning it, like how [ParseURL] does).
No description provided by the author
Query makes a 'query' XRPC request to the provided URL (passed in 'url'), putting the results into 'dst'.
SetUserAgent sets the User-Agent in XRPC requests.
Subscribe makes a 'subscribe' XRPC request for the provided XRPC URL in 'url'.

# Constants

an alternative name for "procedure" so that all the request-types can be a verb.
No description provided by the author
No description provided by the author
No description provided by the author
example: "xrpc://public.api.bsky.app/app.bsky.actor.getProfile?actor=reiver.bsky.social".
example: "xrpc-unencrypted://localhost/app.bsky.actor.getProfile?actor=reiver.bsky.social".

# Structs

URL represents an 'xrpc' and 'xrpc-unencrypted' URL.

# Interfaces

Iterator represents an iterator.