MildServer - A Simple Web Server for APL
Warning: This page is very much work in progress and probably ends quite abruptly. Hope to have the first revision completed by the end of Sunday December 28th.
The MildServer is an experimental framework for simply developing web applications in APL. The main goals of the MildServer project are:
1. Provide a framework which makes it possible for anyone who can write an APL function to turn it into a web page without having to learn much. 2. Experiment with the use of APL code in Unicode files to run an "Open Source" project.
Although the APL code is intended to be "open source", Dyalog APL Version 12.0. is required as the engine for the MildServer - if you don't have it you should be able to get a free or cheap version from the Dyalog Download Zone. Dyalog v12 is the only component required to host your own web server.
Except for a "bootstrap" workspace, all the code which implements the framework itself and the web applications built upon it are stored in Unicode text files, and the framework is intended to be easy to extend. The project is maintained using SubVersion: If it takes off as an open source project, the idea is to expose this subversion server to contributors.
What IS a Web Server Anyway?
A Web Server is a process running on a machine somewhere, which accepts connections via TCP/IP. Over these connections, the Web Server and its client (typically a "Web Browser") communicate using a protocol called HyperText Transfer Protocol, or HTTP. The incoming HTTP requests typically contain commands to retrieve a "resource". For example, "GET index.htm" would be a command to retrieve the contents of a named page. If the MildServer is working according to its design, you should not need to learn anything about TCP/IP or HTTP - this should all be handled automatically.
HTTP responses generally contain text in a format called HyperText Markup Language - or HTML. You WILL need to learn some basic HTML in order to write Web Applications. Although the MildServer contains functions which will help you generate HTML, you will need to know the basic principles of HTML in order to feel comfortable using them. It is a good idea to spend 20-30 minutes looking at the beginning of one of the many excellent HTML tutorials available on the internet.
Much of the information on the internet is in the form of static web pages: These are simply text files containing text marked up as HTML. When you request one of these pages from a Web Server, it simply transmits the content of the file to the client. The fact that a web page is static doesn't mean that it never changes: Your application could be updating the HTM files every few seconds with the latest information that you want to make available.
In addition to serving up static web pages, most Web Servers provide functionality which makes it possible to provide dynamic content:
Scripting: Most Web Servers allow pages to contain embedded code (or "script") which is executed when the resource is retrieved. This allows you to serve up web pages which provide a "user interface", and execute code on the server in response to input from the user.
Sessions: In order to support "applications" using scripting, Web Servers have ways to detect that a sequence of HTTP requests constitute a session. Script code can save session-related data on the server and access it during subsequent requests.
Security: Web Servers can require that the user log in, in order to access all or part of the web site.
Dynamic MildServer Pages
Imagine that we want to implement a very simple interactive Web Page containing a single edit field which we can reverse by clicking on a button:
The code required to implement the above page using the MildServer is:
:Class Reverse : MildPage :Include #.HTMLInput ⍝ Useful functions for creating HTML pages :Field Public Name←'' ⍝ Name of edit field :Field Public Action←'' ⍝ All action buttons have this name ∇ Render req;html;tbl :Access Public DoAction ⍝ If a button was pressed, deal with it html←'<br>Enter Text: ' html,←'Name'Edit Name ⍝ An "Edit" called "Name" containing the Name html,←'<br><br>' html,←'Action'Submit'Reverse' ⍝ A button named 'Action' with Caption 'Reverse' html,←'Action'Submit'Clear' ⍝ ... another button named 'Action' html←req('submit'Form)html ⍝ Put a 'submit' form around it html,←'a href="/"'Enclose'Home' ⍝ A link back to the index page req.Return html ∇ ∇ DoAction :Select Action :Case 'Clear' ⋄ Name←'' :Case 'Reverse' ⋄ Name←⌽Name :EndSelect ∇ :EndClass