How to Create and Run a REBOL CGI Web Page

An Introduction to Running REBOL/Core Scripts on the Internet

© Mark Alexander Bain

Jul 24, 2009
How to Create and Run a REBOL CGI Web Page, Mark Alexander Bain
A programmer can quickly create business rules by using REBOL/View, but by with a CGI application with REBOL/Core they can enable anyone with Internet access to run it.

Any programmer wanting (or needing) to start looking at business rules for an organisation can't go far wrong by starting with REBOL (see An Introduction to the REBOL Programming Language and How to Create a REBOL Dialect). In a very short time they will be able to build the business rules from any analysis that they have carried out by using REBOL/View.

However, this does not really give give the developer a suitable way of delivering these business rules (or dialects) to a mass audience. For that they will need to turn to something like a CGI (Common Gateway Interface) web page. Fortunately that's exactly what REBOL (the Relative Expression-Based Object Language) can give them.

Obtaining REBOL

There are a number of versions of REBOL available (both free and commercial) and the normal starting point is the free REBOL/View. The programmer may use this to create and run the REBOL dialects that can model an organisation' business rules and processes.

However, for a CGI application the programmer will need the REBOL/Core version. This is still free but is designed for server use and has no GUI (Graphical User Interface). Once they've downloaded this to their web server then the programmer is ready to create their first REBOL CGI Page.

Starting CGI Programming

One of the pleasures of working with web servers such as Apache is that they really don't care which programming language a programmer uses. All they the web server is interested in is where to find the language's interpretor, and the programmer tells the web server about this by setting the shebang line. This is always the first line of the CGI script and in REBOL/Core's case the shebang line will look something like:

#!C:\REBOL\rebcore -c

Here rebcore is being run in CGI mode (denoted by the use of the -c flag).

It's worth noting at this point that the REBOL/Core executable can actually be placed in any directory on the web server and can be renamed (for example to "rebol"). Of course the programmer must update the shebang line appropriately.

Only one other line is essential - the first output to the browser must be the HTML header definition:

[REBOL]
print "content-type: text/html^/"

This could now be run as a CGI file, although it will only show a blank page. Therefore the programmer can add some HTML:

print "<h1>Hello World</h1>"

If this code in now saved into a file in the web server cgi-bin directory then it can be run by anyone with Internet access to the server.

Running a REBOL Script on the Internet

All that's require now for someone to run the REBOL script is a web browser and the address of the web server. For example if it is saved as "hello.r" then it could be accessed by the URL http://localhost/cgi-bin/hello.r, and the user would see the text displayed in their web browser (as seen in figure 1 at the bottom of this article).

In this way a programmer can go on to create a set of business rules that can be accessed by anyone in their organisation, and the user need know nothing about REBOL at all. All they will need to know is how to use a web browser.


The copyright of the article How to Create and Run a REBOL CGI Web Page in Computer Programming Languages is owned by Mark Alexander Bain. Permission to republish How to Create and Run a REBOL CGI Web Page in print or online must be granted by the author in writing.


How to Create and Run a REBOL CGI Web Page, Mark Alexander Bain
Figure 1 A Simple REBOL CGI Web Page, Mark Alexander Bain
     


Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo