Downloading a file from the internet 

Sometimes your app needs to get files from a website. Currently, read can do this for you using the HTTP protocol:

read http://www.red-lang.org/index.html

This gives the following string as return value:

;== {<!DOCTYPE html>^/<html class='v2' dir='ltr' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xml

This string can be captured in a data variable for further processing: 

data: read http://www.red-lang.org/index.html

If you're only interested in a part of the web page, use copy/part:

data: copy/part read http://www.red-lang.org/index.html 15; == "<!DOCTYPE html>"

You can also write it out to a local file, all in ...

Get Learn Red - Fundamentals of Red now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.