talk to your urbit from haskell
Go to file
2020-11-13 14:52:04 -05:00
Urbit add arg doc 2020-10-23 13:21:19 -04:00
.ghci init with 'connect' working 2020-08-27 08:34:41 -04:00
.gitignore Ignore dist 2020-10-23 10:16:03 -04:00
.travis.yml fix build and debug ci 2020-10-19 15:27:32 -04:00
default.nix basic build infrastructure 2020-09-16 20:49:49 -04:00
fakezod.sh ci: fix port 2020-10-12 11:53:52 -04:00
LICENSE fix build 2020-10-12 10:23:14 -04:00
Main.hs basic build infrastructure 2020-09-16 20:49:49 -04:00
README.md Add example to readme 2020-11-13 14:52:04 -05:00
shell.nix cleanup and more docs 2020-10-23 10:07:02 -04:00
test.hs add note to test 2020-10-22 18:15:14 -04:00
urbit-airlock.cabal cleanup and more docs 2020-10-23 10:07:02 -04:00
urbit-airlock.nix cleanup and more docs 2020-10-23 10:07:02 -04:00

Haskell Urbit API

License MIT Hackage

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

The "Urbit Airlock" 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-airlock 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.Airlock

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