Difference between revisions of "M2Web Tutorials"
Line 6: | Line 6: | ||
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? | 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: | + | A: Every URL addressed to the server host get processed by a script file |
− | routine ^htCGI ( http://vista.vmth.ucdavis.edu/rtn/htCGI ). This | + | (m2web.cgi) that calls MUMPS (GT.M) to run the routine ^htCGI ( http://vista.vmth.ucdavis.edu/rtn/htCGI ). This is described in a setup document at http://vista.vmth.ucdavis.edu/home/index/48.html. ^htCGI uses helpers to handle the basic HTTP/CGI request/response cycle. |
The HTTP headers are processed into local array | The HTTP headers are processed into local array | ||
Line 38: | Line 38: | ||
Q: How does one specify the function that ^htCGI is to use for handling a request? | Q: How does one specify the function that ^htCGI is to use for handling a request? | ||
− | A: | + | A: When ^htCGI is called, information from the URL is passed in. So, for example, with the URLs: |
− | |||
− | |||
− | |||
− | So, for example, with the URLs: | ||
http://vista.vmth.ucdavis.edu/rtn/... | http://vista.vmth.ucdavis.edu/rtn/... | ||
Line 57: | Line 53: | ||
'query' | 'query' | ||
− | The corresponding handlers are the MUMPS routines ^htRtn, ^htGo, | + | And these values are loaded into htRsrc. The corresponding handlers are the MUMPS routines ^htRtn, ^htGo, ^htEcho, and ^view2ht. |
− | ^htEcho, ^view2ht. | ||
In ^htCGI, the following code can be seen: | In ^htCGI, the following code can be seen: |
Revision as of 14:52, 12 October 2006
(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: 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 ( http://vista.vmth.ucdavis.edu/rtn/htCGI ). This is described in a setup document at http://vista.vmth.ucdavis.edu/home/index/48.html. ^htCGI uses helpers to 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. For example
http://vista.vmth.ucdavis.edu/echo?dbfile=19&index=Name&format=OptnNo;Name;MenuText
will lead to:
htInput("dbfile")=19 htInput("index")="Name" htInput("format")="OptNo;Name;MenuText"
One can try to change "query" to "echo" in the URL above to see the two arrays
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: When ^htCGI is called, information from the URL is passed in. 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'
And these values are loaded into htRsrc. The corresponding handlers are the MUMPS routines ^htRtn, ^htGo, ^htEcho, and ^view2ht.
In ^htCGI, the following code can be seen:
set htHandler=^htCGI("resource",htRsrc,htMethod) set 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.