Syllable Gets First REBOL Binding, With cURL

Syllable now has its first separate REBOL binding (screenshot on Syllable Desktop). The project created a binding with the popular cURL library, which is included in Syllable as its networking library. Documentation and downloads for Syllable, Linux and Windows are available here. The binding will be demonstrated at the upcoming REBOL & Boron conference.

The current version of REBOL 3 for Syllable interfaces with the system at the POSIX level. Beyond that, you can write your own bindings with system and user libraries. Bindings are written as REBOL 3 extensions. Amazingly, and just like the core REBOL 3 interpreter library, Syllable Desktop can run the Linux binary of the cURL binding unchanged, so that the same binary can be shared between Syllable Desktop and Syllable Server. This is possible because the interfaces between REBOL 3 and its extensions are designed for maximal portability, to avoid dependency hell.

The binding consists of a dynamic (shared) library; one single, binary file. On Syllable, either Desktop or Server, installation consists of just dropping it into place, exactly like native Syllable drivers and plug-ins. On other systems, installation may be more complicated.

REBOL has network protocols built in, but the new REBOL version 3 doesn’t have many of the protocols of REBOL 2 yet. The cURL binding fills this gap, and also provides missing features such as SSL and proxy support, and even some protocols that REBOL 2 never had. The exact protocol support depends on the cURL version that you use. Here’s a basic programming example that reads a page from an SSL encrypted website:

import %cURL-binding.so
session: curl/new-session
curl/read session data: copy #{}
curl/verify-peer session off
curl/do session https://github.com/carls/R3A110
curl/end-session session
result: to-string data

cURL is very powerful and flexible, and the REBOL binding gives you an easy way to access its capabilities. For example, if you need to do special web programming to make a website think that your program is a human user, custom headers can be set that will be sent to the server along with a request:

session: curl/new-session
curl/headers session [
    "Referer: ..."
    "User-Agent: ..."
    "Cookie: name1=content1; name2=content2;"
]

Advanced communication with REBOL is possible in both directions. A callback that provides progress status can be added that is written in REBOL, but is called periodically by cURL. Here’s an example, including error checking:

progress: func [
    download-goal [decimal!] download-now [decimal!]
    upload-goal [decimal!] upload-now [decimal!]
][
    print [
        "Read" to-integer download-now
        "of" to-integer download-goal "bytes"

    ]
    0  ; Return non-zero to abort transfer
]
session: curl/new-session
unless all [
    curl/progress session self 'progress
    curl/read session data: copy #{}
    curl/do session http://rebol.com
][
    do make error! second curl/session-error session
]
curl/end-session session
result: to-string data

9 Comments

  1. 2011-02-18 11:04 pm
    • 2011-02-18 11:51 pm
      • 2011-02-19 9:19 am
        • 2011-02-19 2:56 pm
          • 2011-02-19 5:30 pm
          • 2011-02-19 7:54 pm
  2. 2011-02-19 12:39 am
    • 2011-02-19 1:24 am
  3. 2011-02-22 2:57 pm