WebGate

Artifact Content
Login

Artifact c87296211939d0f5eb3580c55c014f872c630487:

Wiki page [Defining Resources] by murphy 2011-09-23 21:41:53.
D 2011-09-23T21:41:53.612
L Defining\sResources
U murphy
W 1542
<h1>Defining Resources</h1>

The easiest way to define a resource for the WebGate framework to serve is to use the syntax
<verbatim>
  (define-resource (ID STEP ... PARAMETERS)
    BODY ...)
</verbatim>

The <tt>ID</tt> is bound to the handler procedure with the given <tt>BODY</tt>. Each <tt>STEP</tt> can be an identifier or a string. An identifier becomes an argument to the handler procedure and will be bound to a path component when the <tt>BODY</tt> is evaluated, a string indicates a fixed path component. The identifier <tt>PARAMETERS</tt> becomes the final argument to the handler procedure and will be bound to a hash table of parameters when the <tt>BODY</tt> is evaluated (see [Interpreting Parameters]).

When WebGate receives a request, it splits the path of the resource into components at instances of "/" and then looks up a handler registered for a matching sequence of components. A literal path component used during handler definition matches an equal string in the incoming resource path, a variable path component in the definition matches any incoming component. Literal path components in the definition take precedence in case the path resolution is ambiguous.

While processing a request you may wish to generate a URI that can be used to refer to a certain resource. This can be done using the procedure
<verbatim>
  (resource-uri RESOURCE ARG ...) => STRING
</verbatim>

Each <tt>ARG</tt> passed to <tt>resource-uri</tt> is used to fix a variable path component of the given <tt>RESOURCE</tt>.

Z 285d0850381896dc518caa68f400abb3