7Grabbing JSON from some url is very easy.
9`strandio` includes the `fetch-json` function which will handle the http request and response parsing and just return unformatted json data.
11Here's a simple thread that will:
13- grab JSON of the latest base-hash from https://www.whatsthelatestbasehash.com/latesthash.json
14- grab JSON of a list of all base-hashes with version info from https://www.whatsthelatestbasehash.com/all.json
16- check `all.json` includes the latest base-hash
17- print the details of the latest base-hash to the dojo
19#### `latest-hash.hoon`
24=, strand=strand:spider
27++ url-1 "https://www.whatsthelatestbasehash.com/latesthash.json"
28++ url-2 "https://www.whatsthelatestbasehash.com/all.json"
63;< js-latest=json bind:m (fetch-json url-1)
64;< js-all=json bind:m (fetch-json url-2)
65=/ latest `latest-sur`(latest-format js-latest)
66=/ all `(list all-sur)`(all-format js-all)
67=/ res (skim all |=(a=all-sur =(hash.a hash.latest)))
69 %- (slog leaf+"Not Found" ~) (pure:m !>(~))
70%- (slog leaf+"Hash: {(trip hash.i.res)}" ~)
71%- (slog leaf+"Pill? {?:(pill.i.res "Yes" "No")}" ~)
72%- (slog leaf+"Version: {(trip version.i.res)}" ~)
73%- (slog leaf+"Published: {(trip published.i.res)}" ~)
74%- (slog leaf+"Release: {(trip release.i.res)}" ~)
78Save it as `/ted/latest-hash.hoon`, `|commit %home` and run it with `-latest-hash`. You should see something like:
82Hash: 0vj.dqqil.77m3k.a7v8d.mvrmi.8mavk.0a2nl.te6i6.cstfa.1ko6e.872gd
85Published: ~2021.3.10..02.20.48
86Release: https://github.com/urbit/urbit/releases/tag/urbit-os-v2.39
92`fetch-json` takes a url as a tape, so we've added a core with the urls like:
97++ url-1 "https://www.whatsthelatestbasehash.com/latesthash.json"
98++ url-2 "https://www.whatsthelatestbasehash.com/all.json"
102...then just called `fetch-json` like:
105;< js-latest=json bind:m (fetch-json url-1)
108We've added formatting and structure arms like:
125...to turn it from `json` to a noun with faces. You can have a look at the JSON formatting functions under `dejs:format` in `zuse.hoon` for how to deal with the various json types.
127After that it's just some ordinary list logic and printing.
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list