net.*, resources and tasks with pending and failure.
net
Requests from the page. Every call waits and can fail, and none says async or await. These ask for files in public/, which ship beside the page as they are.
net.getJSON in, json out. The let's type is the shape the rows take.
Nothing asked for yet.
net.text and net.bytesThe same request, read as text or as bytes. Bytes have a url(): here they are shown as the picture they are.
Nothing asked for yet.
HeadersA last argument {headers: {…}} is passed to fetch, on any of the calls. A file server ignores them: an API reads them.
x-asked-bya header of our own
sent with the request
accept: application/json
x-asked-by: the playground
post, put, del: failing, and handledNothing here can take a write: a file server answers 404 or 405, or with something that is not JSON. Each call says what to do then with else err => …, and the page goes on.
Press one: the failure arrives as words, not as a broken page.
Resources and tasks
A resource is a value loaded in the background. A task is statements that run when its part of the page opens.
resource … elseIt loads at once, and again whenever the state its call reads changes. Its else is its value until then, and on failure.
the call now
net.get("net-planets.json")
pending(bodies)false
failed(bodies)false
8 rows
name
kind
radius, km
moons
Mercury
planet
2440
0
Venus
planet
6052
0
Earth
planet
6371
1
Mars
planet
3390
2
Jupiter
planet
69911
95
Saturn
planet
58232
146
Uranus
planet
25362
28
Neptune
planet
24622
16
task loadA named task runs when the page opens and is also an action: call it again, and ask after it with pending and failure.
Ask for a file that is not therenet-note.txt
pending(load)false
ran 1 time
what it loaded last
This is public/net-note.txt.
A file in public/ beside the entry ships as it is,
and net.text reads it as text.
x? and x else fallbackA call that can fail must be settled where it is made: pass it on with ?, or say what to have instead.
Two of these files exist and two do not. None of the four stops the action.
Actions that wait
pending, failed and failure work on an action as on a resource.
fail("…")?, pending(save), failure(save)With no title the action ends itself with fail. With one it reads a file, then posts to a server that is not there: the ? stops it, and failure(save) has the words.
pending(save)false
failed(save)false
Press Save with the field empty, then with a title.