Size: 6540
Comment:
|
Size: 6743
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 70: | Line 70: |
=== How it Works === If the MildServer is asked to retrieve a file which has the extension ".dyalog" or ".msp" (MildServer Page), it expects the file to contain the source Dyalog APL Class, and this class is expected to have a public method called '''Render'''. The MildServer will call Render with an instance of the HTTPRequest class as the right argument; this object contains information extracted from the incoming HTTP request. The Render function is expected to call one of the following methods on the HTTP request object, before it ends: |
== How it Works == When the MildServer is asked to retrieve a file which has the extension ".dyalog" or ".msp" (MildServer Page), it expects the file to contain the source Dyalog APL Class, and this class is expected to have a public method called '''Render'''. The MildServer will call Render with an instance of the HTTPRequest class as the right argument; this object contains information extracted from the incoming HTTP request. The Render function is expected to call one of the following methods on the HTTP request object, before it ends: |
Line 75: | Line 75: |
* req.ReturnFile (to return the contents of an existing file) | * req.!ReturnFile (to return the contents of an existing file) |
Line 88: | Line 88: |
== Input Parameters == The MildServer extracts parameter names and values from the incoming HTTP request (for more about how parameters are embedded in HTTP requests, see MildServerParameters). |
MildServer - A Simple Web Server for APL
Warning: This page is very much work in progress and probably ends quite abruptly. I expect to continue to add a page or two each day between XMAS and New Year...
The MildServer is an experimental framework for simply developing web applications in APL. The main goals of the MildServer project are:
- 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.
- 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 :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
How it Works
When the MildServer is asked to retrieve a file which has the extension ".dyalog" or ".msp" (MildServer Page), it expects the file to contain the source Dyalog APL Class, and this class is expected to have a public method called Render. The MildServer will call Render with an instance of the HTTPRequest class as the right argument; this object contains information extracted from the incoming HTTP request. The Render function is expected to call one of the following methods on the HTTP request object, before it ends:
- req.Return (to respond with some HTML, as in the above example)
- req.Fail (to set an HTTP failure code)
req.ReturnFile (to return the contents of an existing file)
In this case, the HTML produced is:
<form action="/reverse.dyalog" method="submit"> <br>Enter Text: <input type=text size=10 id="Name" name=Name value="nevohteeB"> <br><br><input type="submit" name="Action" value="Reverse" > <input type="submit" name="Action" value="Clear" > </form> <a href="/">Home</a>
Input Parameters
The MildServer extracts parameter names and values from the incoming HTTP request (for more about how parameters are embedded in HTTP requests, see MildServerParameters).
To Do
- Describe how parameters are handled
- Describe the functions in the HTMLInput namespace
- Describe the contents of the HTTPRequest argument
Talk about how the MildServer implements Sessions and Security