M2Web Tutorials

From VistApedia
Revision as of 14:32, 12 October 2006 by Kdtop (talk | contribs)
Jump to: navigation, search

Back to M2Web Overview

(Below is edited/compiled from emails with Jim Self)


Q: How do we go from user request, via URL, to Apache serving web pages on the server, into GT.M Mumps code, and then back out to Apache and then to the user's web browser?

A: Web requests handled by M2Web start MUMPS execution with the routine ^htCGI ( http://vista.vmth.ucdavis.edu/rtn/htCGI ). This routine and helpers handle the basic HTTP/CGI request/response cycle.

The HTTP headers are processed into local array htCGI(headerName)=value by routine ^htCGI1 ( http://vista.vmth.ucdavis.edu/rtn/htCGI1 ) and named inputs are processed into local array htInput(inputName)=value by routine ^htCGI2.

Additional ht* local variables are defined in ^htCGI1 that provide concise reference to the context and character of each given request.

When an application handler starts up, it will find the inputs in local array htInput. From example below:

 htInput("dbfile")=19
 htInput("index")="Name"
 htInput("format")="OptNo;Name;MenuText"

Change "query" to "echo" in the URL above to see the two arrays

http://vista.vmth.ucdavis.edu/echo?dbfile=19&index=Name&format=OptnNo;Name;MenuText

This display is provided by routine ^htEcho ( http://vista.vmth.ucdavis.edu/rtn/htEcho ), a simple application handler that illustrates a basic HTML and CGI response. It can be a useful tool for basic diagnostics when developing a new application.


Q: How does one specify the function that ^htCGI is to use for handling a request? A: every URL addressed to the server host get processed by a script file (m2web.cgi) that calls MUMPS (GT.M) to run the routine ^htCGI. This is described in a setup document at http://vista.vmth.ucdavis.edu/home/index/48.html So, for example, with the URLs:

http://vista.vmth.ucdavis.edu/rtn/...
http://vista.vmth.ucdavis.edu/go
http://vista.vmth.ucdavis.edu/echo?...
http://vista.vmth.ucdavis.edu/query/?...

The key handlers/functions/"resources" (recall that URL stands for Universal Resource Locator) to use are:

 'rtn'
 'go'
 'echo'
 'query'

The corresponding handlers are the MUMPS routines ^htRtn, ^htGo, ^htEcho, ^view2ht.

In the code for ^htCGI, the following line can be seen:

Set htHandler=^htCGI("resource",htRsrc,htMethod),htAuth=$Get(^(htMethod,"ACCESS"))

And this is where the resource from the URL (e.g. 'rtn') is mapped to '^htRtn'. If one were to add a new resource, the programmer would need to "register" itself with M2Web such that there is an entry in ^htCGI("resource",htRsrc,htMethod))? And if everything is OK, then htHandler will point to the handler for the given request. It will contain M code to launch the handler, like this:

do @htHandler

There is a configuration utility (/resedit) that you can use to review and enter/edit resource definitions. See http://vista.vmth.ucdavis.edu/resedit They can also be viewed and edited directly from /go.

Q: Can any user access any resource? A: Basic access restrictions are controlled by the "ACCESS" attribute of a given method for a given resource which is loaded into local variable htAuth. Login is required unless htAuth="" and htNoSec=0.


Q: What other functions does M2Web provide? A: I have a different set of utilities in M2Web (see http://vista.vmth.ucdavis.edu/rtn/view*) for traversing and processing records defined by Fileman (or otherwise). These make use of ^iterator and variable names derived from Fileman field labels to make extremely concise yet readable processing specifications. Using these utilities makes applications routines, smaller, simpler, more readable, and often more general also.

- example: http://vista.vmth.ucdavis.edu/query/?dbfile=19&index=Name&format=OptnNo;Name;MenuText

This

* index=Name specifies iteration over the "B" index of file 19 (OPTION). 
* "OptnNo" is the variable name for the (IEN) of this file
    so "index=OptnNo" would specifiy iteration over the IEN. 
* "find" Optional parameter -- further refine the iteration.
* "filter" Optional parameters -- further refine the iteration.
* "format=OptnNo;Name;MenuText" is optional. 
   It specifies 3 output fields per data record. 
   Default output is an HTML table but many other possibilities 
     are readily available.

...