This is based on the standard JavaScript fetch
method, with these differences:
- If the server successfully returns a
Response
object, this calls thearrayBuffer()
on theResponse
and returns theArrayBuffer
result. You can use thatArrayBuffer
as is. If you want to convert it to text, pass it toOrigami.string
. - If the
url
ends in an file extension for a known file type, Origami will attach anunpack
method to the returnedArrayBuffer
. You can invoke that method to process the content using the handler associated with that file extension. Additionally, when called in Origami code, you can access data properties directly from the result of theOrigami.fetch
call.
Example: if a given URL returns a YAML resource:
$ ori https://weborigami.org/samples/cli/greetings.yaml
Alice: Hello, Alice.
Bob: Hello, Bob.
Carol: Hello, Carol.
Then these commands are equivalent:
$ ori "Origami.fetch('https://weborigami.org/samples/cli/greetings.yaml').Alice"
Hello, Alice.
$ ori "(https://weborigami.org/samples/cli/greetings.yaml).Alice"
Hello, Alice.
Because Origami automatically evaluates a URL in an Origami expression, it is not generally necessarily to call Origami.fetch
. However, Origami.fetch
may be useful in certain cases like using a Tree.map
to extract a set of URLs from data and then fetch the corresponding resources.