This is based on the standard JavaScript fetch method, with these differences:
- If the server successfully returns a
Responseobject, this calls thearrayBuffer()on theResponseand returns theArrayBufferresult. You can use thatArrayBufferas is. If you want to convert it to text, pass it toOrigami.string. - If the
urlends in an file extension for a known file type, Origami will attach anunpackmethod 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.fetchcall.
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.