on master help sign in
add iris docs
commit0671f0f39d90421acee59a370ae0da86522a825a authortinnus-napbus <admin@tinnus-napbus.xyz> dateThu 29 Jul 2021, 01:05 (5 years ago) parent5c10d5b
6 files changed+238−191
content/docs/arvo/iris/_index.md+16 content/docs/arvo/iris/data-types.md+54 content/docs/arvo/iris/example.md+88 content/docs/arvo/iris/iris-api.md−191 content/docs/arvo/iris/iris.md+17 content/docs/arvo/iris/tasks.md+63
content/docs/arvo/iris/_index.md+16
@@ -5,3 +5,19 @@ sort_by = "weight"
55template = "sections/docs/chapters.html"
66insert_anchor_links = "right"
77+++
8+
9+## [Overview](@/docs/arvo/iris/iris.md)
10+
11+A brief overbview of Iris, Urbit's HTTP client vane.
12+
13+## [Data Types](@/docs/arvo/iris/data-types.md)
14+
15+Reference documentation of the data types used by Iris.
16+
17+## [API Reference](@/docs/arvo/eyre/tasks.md)
18+
19+The `task`s Iris takes and the `gift`s it returns.
20+
21+## [Example](@/docs/arvo/iris/example.md)
22+
23+An example of using Iris to fetch a remote HTTP resource.
content/docs/arvo/iris/data-types.mdnew file+54
@@ -0,0 +1,54 @@
1++++
2+title = "Data Types"
3+weight = 2
4+template = "doc.html"
5++++
6+
7+Iris itself only has three structures defined in `lull.hoon`, but it also uses [$http](@/docs/arvo/eyre/data-types.md#http) structures which are shared between Iris and Eyre. The `$http` structures are detailed in the [Eyre](@/docs/arvo/eyre/data-types.md) Data Types documentation.
8+
9+# `$client-response`
10+
11+```hoon
12++$ client-response
13+ $%
14+ $: %progress
15+ =response-header:http
16+ bytes-read=@ud
17+ expected-size=(unit @ud)
18+ incremental=(unit octs)
19+ ==
20+ [%finished =response-header:http full-file=(unit mime-data)]
21+ [%cancel ~]
22+ ==
23+```
24+
25+This structure represents data which Iris has fetched from a remote HTTP resource, and is what's returned in a `%http-response` `gift` (see the [%request](@/docs/arvo/iris/tasks.md#request) documentation for details) by Iris to the app or thread which requested it. There are three kinds of `client-response` - `%progress`, `%finished` and `%cancel`. A `%progress` `client-response` is a partial response, such as when an HTTP response is split into multiple separate chunks. A `%finished` `client-response` is the final complete, assembled and parsed HTTP response. A `%cancel` `client-response` is sent when the runtime cancels the request for some reason.
26+
27+Note that at the time of writing, **neither `%progress` nor `%cancel` `client-response`s are implemented**, so in practice you'll only ever get a single `%finished` `client-response`.
28+
29+In a `%progress` `client-response`, the [$response-header:http](@/docs/arvo/eyre/data-types.md#response-header-http) contains the HTTP status code and headers. The `bytes-read` field is the total number of bytes fetched so far. The `expected-size` field is the total size specified in the content-length header if it has one. The `incremental` field is the data received since the last `%http-response`.
30+
31+In a `%finished` `client-response`, the `full-file` is the complete body of the HTTP message as a (maybe) [$mime-data](#mime-data).
32+
33+# `$mime-data`
34+
35+```hoon
36++$ mime-data
37+ [type=@t data=octs]
38+```
39+
40+Unvalidated mime data that has been fetched from a remote HTTP resource.
41+
42+# `$outbound-config`
43+
44+```hoon
45++$ outbound-config
46+ $:
47+ redirects=_5
48+ retries=_3
49+ ==
50+```
51+
52+This structure is used in a [%request task](@/docs/arvo/iris/tasks.md#request) to specify settings for an HTTP request. The `redirects` field specifies the number of redirects to automatically follow before failing, and defaults to 5. The `retries` field specifies the number of times to retry a failed request before giving up, and defaults to 3.
53+
54+Note that at the time of writing, **neither redirects nor retries have been implemented**, so these settings will not do anything and you can just use the bunt value in all cases.
content/docs/arvo/iris/example.mdnew file+88
@@ -0,0 +1,88 @@
1++++
2+title = "Example"
3+weight = 4
4+template = "doc.html"
5++++
6+
7+Here we'll look at a simple example of fetching a remote HTTP resource with Iris. We'll use the following thread, which you can save in the `/ted` directory of your `%home` desk:
8+
9+`iris-thread.hoon`
10+
11+```hoon
12+/- spider
13+/+ strandio
14+=, strand=strand:spider
15+^- thread:spider
16+|= arg=vase
17+=/ m (strand ,vase)
18+^- form:m
19+=/ url=@t (need !<((unit @t) arg))
20+=/ =request:http [%'GET' url ~ ~]
21+=/ =task:iris [%request request *outbound-config:iris]
22+=/ =card:agent:gall [%pass /http-req %arvo %i task]
23+;< ~ bind:m (send-raw-card:strandio card)
24+;< res=(pair wire sign-arvo) bind:m take-sign-arvo:strandio
25+?. ?=([%iris %http-response %finished *] q.res)
26+ (strand-fail:strand %bad-sign ~)
27+~& +.q.res
28+?~ full-file.client-response.q.res
29+ (strand-fail:strand %no-body ~)
30+(pure:m !>(`@t`q.data.u.full-file.client-response.q.res))
31+```
32+
33+This thread takes a fully qualified URL in a `@t` as an argument. It will ask Iris to fetch the HTTP resource at the given URL by passing it a [%request task](@/docs/arvo/iris/tasks.md#request) containing an HTTP GET [$request:http](@/docs/arvo/eyre/data-types.md#request-http):
34+
35+```hoon
36+=/ url=@t (need !<((unit @t) arg))
37+=/ =request:http [%'GET' url ~ ~]
38+=/ =task:iris [%request request *outbound-config:iris]
39+=/ =card:agent:gall [%pass /http-req %arvo %i task]
40+```
41+
42+In this example, our `request:http` specifies no additional headers and has no body so it has a `~` for each of those fields. Of course in practice if you have headers or data you want to send you would include those.
43+
44+Our thread will take the `%http-response` `gift` that comes back from Iris and debug print it to the terminal so you can have a look at the structure, and then it will cast the body of the HTTP message to a `@t` and print it.
45+
46+Let's try it out:
47+
48+```
49+> -iris-thread 'http://example.com'
50+[ %http-response
51+ client-response
52+ [ %finished
53+ response-header
54+ [ status-code=200
55+ headers
56+ ~[
57+ [key='age' value='212909']
58+ [key='cache-control' value='max-age=604800']
59+ [key='content-type' value='text/html; charset=UTF-8']
60+ [key='date' value='Thu, 24 Jun 2021 04:12:13 GMT']
61+ [key='etag' value='"3147526947+ident"']
62+ [key='expires' value='Thu, 01 Jul 2021 04:12:13 GMT']
63+ [key='last-modified' value='Thu, 17 Oct 2019 07:18:26 GMT']
64+ [key='server' value='ECS (oxr/8328)']
65+ [key='vary' value='Accept-Encoding']
66+ [key='x-cache' value='HIT']
67+ [key='content-length' value='1256']
68+ ]
69+ ]
70+ full-file
71+ [ ~
72+ [ type='text/html; charset=UTF-8'
73+ data
74+ [ p=1.256
75+ q
76+ 224.708.415.080.409.844.273.808.970.700.472.455.882.111.359.8(...truncated for brevity)
77+ ]
78+ ]
79+ ]
80+ ]
81+]
82+```
83+
84+...and here's the data from the HTTP response cast to a `@t`:
85+
86+```
87+'<!doctype html>\0a<html>\0a<head>\0a <title>Example Domain</title>\0a\0a (...truncated for brevity)'
88+```
content/docs/arvo/iris/iris-api.mddeleted−191
@@ -1,191 +0,0 @@
1−+++
2−title = "API Reference"
3−weight = 10
4−template = "doc.html"
5−+++
6−
7−In this document we describe the public interface for Iris. Namely, we describe
8−each `task` that Iris can be `%pass`ed, and which `gift`(s) Iris can `%give` in
9−return.
10−
11−## Returns to Unix
12−
13−Much of what Iris does is translating `task`s from other vanes into `card`s
14−meant for Unix via the `%request` and `%cancel-request` `task`s. What this means in practice is that Iris may be `%pass`ed a
15−`task` via some `duct`, which in response Iris then `%give`s a `gift` to Unix
16−via another `duct`. This `gift` will actually be a response to the `%born`
17−`task` that Iris was `%pass`ed when the Urbit was resumed, which came along the
18−duct to Unix.
19−
20−
21−## Tasks
22−
23−### `%born`
24−
25−Each time you start your Urbit the Arvo kernel calls the `%born` `task` for
26−Iris. This causes Iris to cancel any outstanding http requests and resets all
27−connection states.
28−
29−#### Accepts
30−
31−```hoon
32−[ ~ ]
33−```
34−
35−#### Returns
36−
37−In response to a `%born` `task` Iris `give`s a `%http-response %cancel` `gift`
38−to each outstanding connection.
39−
40−
41−### `%cancel-request`
42−
43−This `task` cancels a previous fetch. Iris knows which request is meant based on the
44−`duct` that the `task` comes on.
45−
46− We note that `%cancel-request` is also a `gift` that Iris can `%give`.
47−
48−#### Accepts
49−
50−```hoon
51−[ ~ ]
52−```
53−
54−#### Returns
55−
56−```hoon
57−[%cancel-request id=@ud]
58−```
59−Receiving this `task` causes Iris to `%give`s a `%cancel-request` `gift` to Unix,
60−which then cancels the request in the runtime. See [Returns to Unix](#returns-to-unix).
61−
62−`id` is obtained via a `(map duct @ud)`, with the `duct` corresponding to one along
63−which the `%cancel-request` `task` came with.
64−
65−
66−### `%crud`
67−
68−`%crud` is called whenever an error involving Iris occurs. It produces a crash
69−report in response.
70−
71−#### Accepts
72−
73−```hoon
74−[p=@tas q=(list tank)]
75−```
76−
77−`p` is the type of error, `q` is the error message.
78−
79−#### Returns
80−
81−Iris does not `%give` a `gift` in response to a `%crud` `task`, but it does
82−`%slip` Dill a `%flog` `task` instructing it to print the error.
83−
84−
85−### `%receive`
86−
87−The `%receive` `task` is used to receive a response from Unix to an `http-request` that
88−was made.
89−
90−#### Accepts
91−
92−```hoon
93−[id=@ud =http-event:http]
94−```
95−
96−`id` is the identification number assigned by Iris to the http connection under
97−consideration. `http-event` is a packet that contains a header and data.
98−
99−#### Returns
100−
101−The response depends on what kind of packet `http-event` is: `%start`,
102−`%continue`, or `%cancel` and whether the `complete` flag is `%.y` or `%.n`.
103−
104−If the packet says to `%start` or `%continue` and `complete=%.n`, Iris will `%give` a
105−`%http-response %progress` `gift`.
106−
107−If the packet says to `%start` or `%continue` and `complete=%.y`, Iris will
108−`%give` a `%http-response %finished` `gift`.
109−
110−If the packet says to `%cancel`, Iris will `%give` a `%http-response %cancel`
111−`gift` in return. The `complete` flag is unused here.
112−
113−
114−### `%request`
115−
116−`%request` is used to fetch a remote resource. `%request` is also a `gift` Iris
117−can `%give`.
118−
119−#### Accepts
120−
121−```hoon
122−[=request:http =outbound-config]
123−```
124−
125−A `$request` consists of the following:
126− - `=method`, the http method, which is one of `CONNECT`, `DELETE`, `GET`,
127− `HEAD`, `OPTIONS`, `POST`, `PUT`, and `TRACE`.
128− - `url=@t`, the URL being requested
129− - `=header-list`, a list of headers to pass with the request,
130− - `body=(unit octs)`, optional data to include in the request.
131−
132− A `$outbound-config` contains the number of redirects and retries that Iris
133− will attempt. By default this is 5 redirects (the recommended limit for the
134− http standard) and 3 retries.
135−
136−#### Returns
137−
138−```hoon
139−[id=@ud request=request:http]
140−```
141−Iris will `%give` a `%request` `gift` to Unix in response to a `%request`
142−`task`. See [Returns to Unix](#returns-to-unix). This `gift`
143−contains the `request` in the original `task` as well as the ID number assigned
144−by Iris for that particular http connection, which is extracted from the input `task`.
145−
146−
147−### `%trim`
148−
149−This `task` is sent by the interpreter to free up memory. It has no effect on Iris.
150−
151−#### Accepts
152−
153−```hoon
154−[ ~ ]
155−```
156−
157−#### Returns
158−
159−This `task` returns no `gift`s.
160−
161−
162−### `%vega`
163−
164−This `task` informs the vane that the kernel has been upgraded. Iris does not do
165−anything in response to this.
166−
167−#### Accepts
168−
169−```hoon
170−[ ~ ]
171−```
172−
173−#### Returns
174−
175−This `task` returns no `gift`s.
176−
177−
178−### `%wegh`
179−
180−This `task` asks Iris to product a memory usage report.
181−
182−#### Accepts
183−
184−This `task` has no arguments.
185−
186−#### Returns
187−
188−When Iris is `%pass`ed this `task`, it will `%give` a `%mass` `gift` in response
189−containing Iris' current memory usage.
190−
191−
content/docs/arvo/iris/iris.mdnew file+17
@@ -0,0 +1,17 @@
1++++
2+title = "Overview"
3+weight = 1
4+template = "doc.html"
5++++
6+
7+Iris is the HTTP client vane.
8+
9+Gall agents and Spider threads pass Iris HTTP requests, Iris makes the request to the specified URL, and finally returns the HTTP response back to the app or thread that requested it.
10+
11+# Iris Documentation Sections
12+
13+- [Data Types](@/docs/arvo/iris/data-types.md) - Reference documentation of the data types used by Iris.
14+
15+- [API Reference](@/docs/arvo/eyre/tasks.md) - The `task`s Iris takes and the `gift`s it returns.
16+
17+- [Example](@/docs/arvo/iris/example.md) - An example of using Iris to fetch a remote HTTP resource.
content/docs/arvo/iris/tasks.mdnew file+63
@@ -0,0 +1,63 @@
1++++
2+title = "API Reference"
3+weight = 3
4+template = "doc.html"
5++++
6+
7+This document details the `task`s that can be sent to Iris. Iris only has a couple of `task`s you can use - [%request](#request) and [%cancel-request](#cancel-request).
8+
9+# `%request`
10+
11+```hoon
12+[%request =request:http =outbound-config]
13+```
14+
15+Fetch a remote HTTP resource.
16+
17+The [$request:http](@/docs/arvo/eyre/data-types.md#request-http) is the request itself and contains the HTTP method, the fully qualified target URL, a list of HTTP headers to be included and maybe the data for the body of the request.
18+
19+The [$outbound-config](@/docs/arvo/iris/data-types.md#outbound-config) specifies the number of redirects to follow before failing and the number of retries to attempt before giving up. The default values are `5` and `3` respectively. As of writing, **retries and auto-following redirects are not implemented**, so what you specify here is irrelevant and you can just use the bunt value of `outbound-config`.
20+
21+## Returns
22+
23+Iris returns a `%http-response` `gift` in response to a `%request` task. A `%response` `gift` looks like:
24+
25+```hoon
26+[%http-response =client-response]
27+```
28+
29+The [$client-response](@/docs/arvo/iris/data-types.md#client-response) contains the HTTP response from the server including the status code, HTTP headers and any data along with its mime type.
30+
31+The `client-response` structure specifies three kinds of responses - `%progress`, `%finished` and `%cancel`. The `%progress` response would contain each chunk of the message as it came in, `%finished` would contain the final assembled message from Vere's buffer, and `%cancel` would be sent if the runtime cancels the request.
32+
33+Note that neither `%progress` partial messages nor `%cancel` responses have been implemented in Vere at the time of writing, so **you will only ever receive a single `%http-response` `gift` with a `%finished` `client-response`**. If the request fails for some reason, you'll still get an empty `%finished` `client-response` with a `504` status code.
34+
35+## Example
36+
37+See the [Example](@/docs/arvo/iris/example.md) document.
38+
39+# `%cancel-request`
40+
41+```hoon
42+[%cancel-request ~]
43+```
44+
45+Cancel a previous request to fetch a remote HTTP resource.
46+
47+A `%cancel-request` `task` does not take any arguments, the [request](#request) to cancel is determined implicitly.
48+
49+## Returns
50+
51+Iris does not return any `gift` in response to a `%cancel-request` `task`. You will also not receive any `gift` back from the original `%request` `task` you've cancelled.
52+
53+# `%receive`
54+
55+```hoon
56+[%receive id=@ud =http-event:http]
57+```
58+
59+Receives HTTP data from outside. This `task` is sent to Iris by the runtime, you would not used it manually.
60+
61+## Accepts
62+
63+The `id` is a sequential ID for the event and the [$http-event:http](@/docs/arvo/eyre/data-types.md#http-event-http) contains the HTTP headers and data.