Defining Resources

Defining Resources

The easiest way to define a resource for the WebGate framework to serve is to use the syntax

  (define-resource (ID STEP ... PARAMETERS)
    BODY ...)

The ID is bound to the handler procedure with the given BODY. Each STEP 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 BODY is evaluated, a string indicates a fixed path component. The identifier PARAMETERS becomes the final argument to the handler procedure and will be bound to a hash table of parameters when the BODY 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

  (resource-uri RESOURCE ARG ...) => STRING

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