@@ -189,7 +189,7 @@ window.ship = "zod";
189189`"zod"` will be replaced with the actual name of the ship in question. You can
190190include this file like:
191191
192−```html
192+```
193193<script src="/session.js"></script>
194194```
195195
@@ -208,8 +208,8 @@ through its channel system.
208208
209209The `Urbit` object will generate a random channel ID that looks like
210210`1646295453-e1bdfd`, and use a path of `/~/channel/1646295453-e1bdfd` for
211−channel communications. Pokes and subscription requests will be sent to that
212−channel. Responses and subscription updates will be sent out to you on that
211+channel communications. Pokes will and subscription requests will be sent to
212+that channel. Responses and subscription updates will be sent out to you on that
213213channel too.
214214
215215Eyre sends out updates and responses on an [SSE] (Server Sent Event) stream for
@@ -274,14 +274,26 @@ question):
274274Here's a simple example that will run `authenticate` for a fakezod when the
275275_Connect_ button is pressed:
276276
277−```html
278−<html> <head> <script
279−src="https://unpkg.com/@urbit/http-api"></script> </head> <body>
280−<button id="start" type="button" onClick="connect()" >Connect</button>
281−</body> <script> async function connect() { window.api = await
282−UrbitHttpApi.Urbit.authenticate({ ship: "zod", url: "localhost:8080", code:
283−"lidlut-tabwed-pillex-ridrup", verbose: true }); document.body.innerHTML =
284−"Connected!"; }; </script> </html>
277+```
278+<html>
279+ <head>
280+ <script src="https://unpkg.com/@urbit/http-api"></script>
281+ </head>
282+ <body>
283+ <button id="start" type="button" onClick="connect()" >Connect</button>
284+ </body>
285+ <script>
286+ async function connect() {
287+ window.api = await UrbitHttpApi.Urbit.authenticate({
288+ ship: "zod",
289+ url: "localhost:8080",
290+ code: "lidlut-tabwed-pillex-ridrup",
291+ verbose: true
292+ });
293+ document.body.innerHTML = "Connected!";
294+ };
295+ </script>
296+</html>
285297```
286298
287299`window.api` can then be used for further communications.
@@ -312,22 +324,45 @@ mark. The `json` argument just contains the message in a string. If for some
312324reason the `hood` agent rejects the poke, "Poke failed!" will be displayed on
313325the page.
314326
315−```html
316−<html> <head> <script
317−src="https://unpkg.com/@urbit/http-api"></script> <script
318−src="/session.js"></script> </head> <body> <input id="msg"
319−type="text" placeholder="Message for ship" /> <button id="submit"
320−type="button" onClick="doPoke()" >Submit</button> <p id="err"></p>
321−</body> <script> document.getElementById("msg") .addEventListener("keyup",
322−function(event) { if (event.keyCode === 13) {
323−document.getElementById("submit").click(); } }) const api = new
324−UrbitHttpApi.Urbit(""); api.ship = window.ship; function doPoke() { const msg =
325−document.getElementById("msg").value; api.poke({ app: "hood", mark: "helm-hi",
326−json: msg, onSuccess: success, onError: error }); } function success() {
327−document.getElementById("msg").value = "";
328−document.getElementById("err").innerHTML = ""; } function error() {
329−document.getElementById("msg").value = "";
330−document.getElementById("err").innerHTML = "Poke failed!"; } </script>
327+```
328+<html>
329+ <head>
330+ <script src="https://unpkg.com/@urbit/http-api"></script>
331+ <script src="/session.js"></script>
332+ </head>
333+ <body>
334+ <input id="msg" type="text" placeholder="Message for ship" />
335+ <button id="submit" type="button" onClick="doPoke()" >Submit</button>
336+ <p id="err"></p>
337+ </body>
338+ <script>
339+ document.getElementById("msg")
340+ .addEventListener("keyup", function(event) {
341+ if (event.keyCode === 13) {
342+ document.getElementById("submit").click();
343+ }
344+ })
345+ const api = new UrbitHttpApi.Urbit("");
346+ api.ship = window.ship;
347+ function doPoke() {
348+ const msg = document.getElementById("msg").value;
349+ api.poke({
350+ app: "hood",
351+ mark: "helm-hi",
352+ json: msg,
353+ onSuccess: success,
354+ onError: error
355+ });
356+ }
357+ function success() {
358+ document.getElementById("msg").value = "";
359+ document.getElementById("err").innerHTML = "";
360+ }
361+ function error() {
362+ document.getElementById("msg").value = "";
363+ document.getElementById("err").innerHTML = "Poke failed!";
364+ }
365+ </script>
331366</html>
332367```
333368
@@ -365,22 +400,47 @@ This example will, upon clicking the "Subscribe" button, subscribe to the
365400update it receives. You can test it by doing something like posting a message in
366401a chat. You can also unsubscribe by clicking the "Unsubscribe" button.
367402
368−```html
369−<html> <head> <script
370−src="https://unpkg.com/@urbit/http-api"></script> <script
371−src="/session.js"></script> </head> <body> <button id="toggle"
372−type="button" onClick="doSub()" >Subscribe</button> <pre
373−id="event"></pre> </body> <script> const api = new
374−UrbitHttpApi.Urbit(""); api.ship = window.ship; const toggle =
375−document.getElementById("toggle"); const event =
376−document.getElementById("event"); function doSub() { window.id = api.subscribe({
377−app: "graph-store", path: "/updates", event: printEvent, quit: doSub, err:
378−subFail }); toggle.innerHTML = "Unsubscribe"; toggle.onclick = doUnsub;
379−event.innerHTML = "Awaiting event"; }; function doUnsub() {
380−api.unsubscribe(window.id); toggle.innerHTML = "Subscribe"; toggle.onclick =
381−doSub; event.innerHTML = "Subscription closed"; }; function printEvent(update) {
382−event.innerHTML = JSON.stringify(update, null, 2); }; function subFail() {
383−event.innerHTML = "Subscription failed!"; }; </script> </html>
403+```
404+<html>
405+ <head>
406+ <script src="https://unpkg.com/@urbit/http-api"></script>
407+ <script src="/session.js"></script>
408+ </head>
409+ <body>
410+ <button id="toggle" type="button" onClick="doSub()" >Subscribe</button>
411+ <pre id="event"></pre>
412+ </body>
413+ <script>
414+ const api = new UrbitHttpApi.Urbit("");
415+ api.ship = window.ship;
416+ const toggle = document.getElementById("toggle");
417+ const event = document.getElementById("event");
418+ function doSub() {
419+ window.id = api.subscribe({
420+ app: "graph-store",
421+ path: "/updates",
422+ event: printEvent,
423+ quit: doSub,
424+ err: subFail
425+ });
426+ toggle.innerHTML = "Unsubscribe";
427+ toggle.onclick = doUnsub;
428+ event.innerHTML = "Awaiting event";
429+ };
430+ function doUnsub() {
431+ api.unsubscribe(window.id);
432+ toggle.innerHTML = "Subscribe";
433+ toggle.onclick = doSub;
434+ event.innerHTML = "Subscription closed";
435+ };
436+ function printEvent(update) {
437+ event.innerHTML = JSON.stringify(update, null, 2);
438+ };
439+ function subFail() {
440+ event.innerHTML = "Subscription failed!";
441+ };
442+ </script>
443+</html>
384444```
385445
386446### Subscribe Once
@@ -417,17 +477,33 @@ printing every `graph-store` update it receives, it will instead just print the
417477first one it receives and close the subscription. Additionally, it sets a five
418478second timeout, and prints an error message if it times out.
419479
420−```html
421−<html> <head> <script
422−src="https://unpkg.com/@urbit/http-api"></script> <script
423−src="/session.js"></script> </head> <body> <button type="button"
424−onClick="doSub()" >Subscribe Once</button> <pre id="event"></pre>
425−</body> <script> const api = new UrbitHttpApi.Urbit(""); api.ship =
426−window.ship; const event = document.getElementById("event"); function doSub() {
427−event.innerHTML = ""; api.subscribeOnce("graph-store","/updates",5000)
428−.then(printEvent, noEvent); }; function printEvent(update) { event.innerHTML =
429−JSON.stringify(update, null, 2); }; function noEvent(error) { event.innerHTML =
430−error; }; </script> </html>
480+```
481+<html>
482+ <head>
483+ <script src="https://unpkg.com/@urbit/http-api"></script>
484+ <script src="/session.js"></script>
485+ </head>
486+ <body>
487+ <button type="button" onClick="doSub()" >Subscribe Once</button>
488+ <pre id="event"></pre>
489+ </body>
490+ <script>
491+ const api = new UrbitHttpApi.Urbit("");
492+ api.ship = window.ship;
493+ const event = document.getElementById("event");
494+ function doSub() {
495+ event.innerHTML = "";
496+ api.subscribeOnce("graph-store","/updates",5000)
497+ .then(printEvent, noEvent);
498+ };
499+ function printEvent(update) {
500+ event.innerHTML = JSON.stringify(update, null, 2);
501+ };
502+ function noEvent(error) {
503+ event.innerHTML = error;
504+ };
505+ </script>
506+</html>
431507```
432508
433509### Scries
@@ -449,16 +525,26 @@ Upon pressing the "Scry Graphs" button, this example will scry the `graph-store`
449525agent's `/keys` endpoint for the list of graphs, and print the resulting JSON
450526data.
451527
452−```html
453−<html> <head> <script
454−src="https://unpkg.com/@urbit/http-api"></script> <script
455−src="/session.js"></script> </head> <body> <button id="scry"
456−type="button" onClick="doScry()" >Scry Graphs</button> <pre
457−id="result"></pre> </body> <script> const api = new
458−UrbitHttpApi.Urbit(""); api.ship = window.ship; async function doScry() { var
459−groups = await api.scry({app: "graph-store", path: "/keys"});
460−document.getElementById("result") .innerHTML = JSON.stringify(groups, null, 2);
461−} </script> </html>
528+```
529+<html>
530+ <head>
531+ <script src="https://unpkg.com/@urbit/http-api"></script>
532+ <script src="/session.js"></script>
533+ </head>
534+ <body>
535+ <button id="scry" type="button" onClick="doScry()" >Scry Graphs</button>
536+ <pre id="result"></pre>
537+ </body>
538+ <script>
539+ const api = new UrbitHttpApi.Urbit("");
540+ api.ship = window.ship;
541+ async function doScry() {
542+ var groups = await api.scry({app: "graph-store", path: "/keys"});
543+ document.getElementById("result")
544+ .innerHTML = JSON.stringify(groups, null, 2);
545+ }
546+ </script>
547+</html>
462548```
463549
464550### Thread
@@ -482,23 +568,44 @@ JSON result of the thread.
482568This example takes a hoon expression (such as `(add 1 1)`), evalutes it with the
483569`graph-eval` thread in the `landscape` desk, and prints the result.
484570
485−```html
486−<html> <head> <script
487−src="https://unpkg.com/@urbit/http-api"></script> <script
488−src="/session.js"></script> </head> <body> <input id="hoon"
489−type="text" placeholder="Hoon to evaluate" /> <button id="submit"
490−type="button" onClick="runThread()" >Submit</button> <pre
491−id="expr"></pre> <pre id="result"></pre> </body> <script>
492−document.getElementById("hoon") .addEventListener("keyup", function(event) { if
493−(event.keyCode === 13) { document.getElementById("submit").click(); } }); const
494−hoon = document.getElementById("hoon"); const expr =
495−document.getElementById("expr"); const result =
496−document.getElementById("result"); const desk = "landscape"; const api = new
497−UrbitHttpApi.Urbit("", "", desk); api.ship = window.ship; async function
498−runThread() { const threadResult = await api.thread({ inputMark:
499−"graph-view-action", outputMark: "tang", threadName: "graph-eval", body: {eval:
500−hoon.value} }); result.innerHTML = threadResult[0].join("\n"); expr.innerHTML =
501−hoon.value; hoon.value = ""; }; </script> </html>
571+```
572+<html>
573+ <head>
574+ <script src="https://unpkg.com/@urbit/http-api"></script>
575+ <script src="/session.js"></script>
576+ </head>
577+ <body>
578+ <input id="hoon" type="text" placeholder="Hoon to evaluate" />
579+ <button id="submit" type="button" onClick="runThread()" >Submit</button>
580+ <pre id="expr"></pre>
581+ <pre id="result"></pre>
582+ </body>
583+ <script>
584+ document.getElementById("hoon")
585+ .addEventListener("keyup", function(event) {
586+ if (event.keyCode === 13) {
587+ document.getElementById("submit").click();
588+ }
589+ });
590+ const hoon = document.getElementById("hoon");
591+ const expr = document.getElementById("expr");
592+ const result = document.getElementById("result");
593+ const desk = "landscape";
594+ const api = new UrbitHttpApi.Urbit("", "", desk);
595+ api.ship = window.ship;
596+ async function runThread() {
597+ const threadResult = await api.thread({
598+ inputMark: "graph-view-action",
599+ outputMark: "tang",
600+ threadName: "graph-eval",
601+ body: {eval: hoon.value}
602+ });
603+ result.innerHTML = threadResult[0].join("\n");
604+ expr.innerHTML = hoon.value;
605+ hoon.value = "";
606+ };
607+ </script>
608+</html>
502609```
503610
504611### Delete Channel
@@ -526,13 +633,10 @@ discarded and a fresh channel ID will be generated.
526633- [Eyre Guide][eyre-guide] - Lower-level examples of using Eyre's external API
527634 with `curl`.
528635- [`http-api` on Github][http-api-src] - The source code for `@urbit/http-api`.
529−- [Software Distribution][dist] - This section of documentation explains how to
530− distribute apps in Urbit, including how to package and serve front-end files.
531636
532637[eyre-ext-ref]: /docs/arvo/eyre/external-api-ref
533638[eyre-guide]: /docs/arvo/eyre/guide
534639[http-api-src]: https://github.com/urbit/urbit/tree/master/pkg/npm/http-api
535−[dist]: /docs/userspace/dist/dist
536640[eyre]: /docs/glossary/eyre
537641[vane]: /docs/glossary/vane
538642[arvo]: /docs/glossary/arvo