MyNixOS website logo
Description

Talk to Urbit from Haskell.

urbit-api is a Haskell library that helps you connect to the Urbit API.

Built on req, conduit, and aeson for stability and simplicity.

Haskell Urbit API

License MIT Hackage builds.sr.ht status

This library helps you talk to your Urbit from Haskell, via HTTP.

The Urbit API is a command-query API that lets you hook into apps running on your Urbit. You can submit commands (called "pokes") and subscribe to responses.

See the test.hs file for some example usages.

Design

The Urbit vane eyre is responsible for defining the API interface. The path to the API is /~/channel/..., where we send messages to the global log (called pokes) which are then dispatched to the appropriate apps. To receive responses, we stream messages from a path associated with the app, such as /mailbox/~/~zod/mc. Internally, I believe Urbit calls these wires.

urbit-api handles most of the path, session, and HTTP request stuff automatically. See the haddocks for more details.

This library is built on req, conduit, and aeson, all of which are very stable and usable libraries for working with HTTP requests and web data.

Example usage

import qualified Data.Aeson as Aeson
import Data.Aeson ((.=))
import qualified Data.Text as Text
import qualified Data.UUID.V4 as UUID

import Urbit.API

main :: IO ()
main = do
  let fakezod = Ship
    { uid = "0123456789abcdef",
      name = "zod",
      lastEventId = 1,
      url = "http://localhost:8081",
      code = "lidlut-tabwed-pillex-ridrup"
    }

  -- Establish connection
  sess <- connect ship

  -- Send a message by poking the chat-hook
  uuid <- UUID.nextRandom
  poke sess ship "zod" "chat-hook" "json" $
    Aeson.object
      [ "message"
          .= Aeson.object
            [ "path" .= Text.pack "/~/~zod/mc",
              "envelope"
                .= Aeson.object
                  [ "uid" .= UUID.toText uuid,
                    "number" .= (1 :: Int),
                    "author" .= Text.pack "~zod",
                    "when" .= (1602118786225 :: Int),
                    "letter" .= Aeson.object ["text" .= Text.pack "hello world from haskell!"]
                  ]
            ]
      ]

TODO

  • fix test suite on travis (OOM when trying to compile urbit)
  • more sophisticated test cases, also use cabal test instead of homegrown thing
  • add an exe that wraps the library with a cli
  • port to ghcjs
  • put some examples in the docs.
Metadata

Version

0.2.0.0

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows