On this page:
11.1 fetch-uri
11.1.1 Exceptions with fetch-uri

11 Utility functions

11.1 fetch-uri

(fetch-uri uri)  string
  uri : string
Downloads the given URI and returns the file path of the downloaded file. A few types of URI mime-types are supported -

text/xml

Any response to the URL with a MIME type string containing “xml” is treated as an XML document and labelled with the ".xml" extension.

image/jpeg, image/png and image/bmp

JPEG and PNG image files are downloaded and given a file path with their respective common file extensions.

text/plain

Gets the extension ".txt". Scheme files also use the text/plain MIME type. So you can load ".scm" files using -

(load (fetch-uri "http://somewhere.com/path/lib.scm"))

11.1.1 Exceptions with fetch-uri

Whenever you access the network, you should guard yourself against exceptional conditions such as connection failures, transfer interruptions, etc. The fetch-uri function raises a few exceptions to let you know about these conditions so you can respond to them. When these exceptions occur, you can choose to abort the operation or continue with, say, a default file. For details about raising and handling muSE exceptions and about the resume continuation, refer to the documentation on the muSE project page.

(resume 'fetch-uri:network-error uri)

Indicates a fundamental problem with connecting to the internet. You can resume when this exception occurs by choosing to use a fixed local file path instead of the downloaded URI. You can resume like this -

(resume "somewhere\blah.jpg")

(resume 'fetch-uri:bad-resource uri)

Indicates that the URI is either badly formatted or is referring to an invalid resource. In this case, you can resume by either using a default URI that is known to work, or a fixed local file, using the resume function.

(resume 'fetch-uri:unsupported uri)

Indicates that the URI is not a http URI or is of a type that cannot be supported for some reason. In this case, you’re allowed to resume by replacing the URI with a default file.

(resume 'fetch-uri:cache-failure uri)

Indicates a problem downloading the URI and storing it in the cache. In this case, you’re allowed to replace it with a local file.