Skip to content

Instantly share code, notes, and snippets.

@tylershuster
Last active November 10, 2020 01:12
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylershuster/74d69e09650df5a86c4d8d8f00101b42 to your computer and use it in GitHub Desktop.
Save tylershuster/74d69e09650df5a86c4d8d8f00101b42 to your computer and use it in GitHub Desktop.
Urbit API Documentation
@liam-fitzgerald
Copy link

Looks good so far @tylershuster !
Worth mentioning:

  • the delete endpoint (kill the channel)
  • the unsubscribe action
  • Error handling of write requests on a channel (the HTTP request will always 204, and you'll get a nack on the eventstream if it fails).
  • You can't poke a foreign ship with a mark other than json.

Maybe also worthwhile to mention the scry and spider APIs, but kind of out of scope as far as just airlock goes.

@Fang-
Copy link

Fang- commented Oct 5, 2020

>scry
>out of scope as far as just airlock goes

Nothing could be further from the truth! Scries make for excellent on-demand data reading interfaces. Use them, and great things will come to you!

Access-Control-Allow-Origin: *

Guessing this is part of your custom setup?

Mostly skimmed this, but looks good! The whole "cookie as only auth method" thing is obviously unwieldy, but ehh. For your dissection of the cookie it might be more accurate to say that "~zod is the name of the ship being logged in as", but I don't think that has real support at the moment.

@tylershuster
Copy link
Author

  • delete and unsubscribe would be good to add
  • thanks for the point about nacks
  • Thanks for the point about poking foreign ships. I might mention it, but it's beyond the scope of this tutorial to delve
  • Thanks for the clarification about logging in as. I don't think it will confuse anyone to be more accurate in this regard
  • Good catch on the origin headers

Scry/Spider:

https://github.com/urbit/urbit/blob/master/pkg/interface/src/logic/api/base.ts#L57-L68

I can read this, but I don't know how to make it useful. Seems like scry and spider are solid, but lacking documentation. Do you have a reference for some basic understanding of them outside of the context of a particular app?

In general I think that this doc makes for a good "here's a basic connection" tutorial but the more urbity stuff (like Structure of a Chat Message) really should be documented elsewhere, and I can't do it because it's so in flux. If you know of a portions of code that are likely to stay the same, I could start to document those and include them when I PR this.

@Fang-
Copy link

Fang- commented Oct 5, 2020

An authenticated GET request on /~/scry/app-name/path.mark scries into %app-name at the /x/path. If the scry fails, 500. If there is no data, 404. If it succeeds, it tries converting the scry result to the %mark (or %mime if no extension specified), and then converting that to the %mime mark. Asking for json is currently most common, but you could ask for %txt or %jam or whatever.

@tylershuster
Copy link
Author

And spider?

@liam-fitzgerald
Copy link

An authenticated POST request on /spider/inputmark/threadname/outputmark.json will attempt to run the threadname thread. It will attempt to convert the JSON in the POST body to inputmark and then use that as the parameters for the thread. Once the thread has completed, spider will attempt to convert the return value of the thread from outputmark to JSON. In the general case, if the thread fails it will return 500. However, if the thread fails with certain messages, it will return a corresponding HTTP status code (see ++thread-http-fail in app/spider.hoon for the mapping and ted/graph/join.hoon for an example of this in use).

@tylershuster
Copy link
Author

Thanks. Considering that graph-store uses this I'm going to have to get my head wrapped around it but it seems a bit...messy for the user just getting started. Do you have simpler examples than the ones I can see in graph.ts? It seems like pretty high cognitive overhead and setup for something that will take a while to use.

I mean, I guess graph-store really eats the world you'll want to know how to interact with it, but hopefully the libraries take care of it for you.

@tylershuster
Copy link
Author

tylershuster commented Oct 5, 2020

@Fang-
Copy link

Fang- commented Oct 5, 2020

spidering

lol, might be more clear to say "running threads" or "starting asynchronous operations" or whatever?

Great work. (:

@tylershuster
Copy link
Author

@liam-fitzgerald, @Fang-, do you have some beginner examples of spidering? thinking of just cutting it if not

@tylershuster
Copy link
Author

Er, "running threads"

@Beasta
Copy link

Beasta commented Oct 7, 2020

🚀

@Fang-
Copy link

Fang- commented Oct 8, 2020

idk if there's any threads you can "just like kick off" super easily, none of the simple ones like -hi etc have mars matching their input...

@tylershuster
Copy link
Author

Well then I will probably just leave a basic syntax and a “here there be monsters” warning. Time to PR

@dclelland
Copy link

Additional airlock in Swift here: https://github.com/dclelland/UrsusAirlock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment