Table of Contents
Procedures can be published to virtual paths of an application server within the hierarchy of a siscweb application. Publishing can be done both interactively at the server-side REPL during development, and in the web.xml file at deployment time. (See the section called “The Adapter Servlet”.)
Requires:
(import siscweb/publish)
Located in:
siscweb.jar
This module provides simple procedures to publish procedures to URL patterns. Patterns can be expressed either as wildcards or regular expressions.
Published procedures accept a single parameter in the form of a request object.
Since the Java HttpServletRequest object is not serializable, it is a good practice to clear any reference to it as soon as possible.
Wildcard patterns can use wildcards and double-wildcards between slashes, such as in "/hello/*" or "/hello/**/world". The first pattern matches requests such as "/hello/there", "/hello/", or even "/hello"; the second pattern matches "/hello/world" as well as "hello/what/a/wonderful/world/".
procedure:
(publish/wildcard url-wildcard-pattern (lambda (request) ...)) => undefined
procedure:(publish/wildcard url-wildcard-pattern symbol) => undefined
Publishes the given procedure
proc
orsymbol
aturl-wildcard-pattern
. Thesymbol
will be looked up at run time every time. This is especially useful during development, since it allows one to redefine the procedure associated tosymbol
without having to republish.When a request is received, the path-info section of the request URL is matched against each published pattern. If a match is found, the corresponding procedure is invoked. The procedure will receive the HTTP request as its only argument.
(publish/wildcard "/hello-world/*" (lambda (request) (set! request #f) (send-html/back `(html (head (title "Hello, world!")) (body (p "Hello, world!"))))))
procedure:
(publish/regexp url-regexp-pattern (lambda (request) ...)) => undefined
procedure:(publish/regexp url-regexp-pattern symbol) => undefined
This function is equivalent to
publish/wildcard
, save for the fact that it accepts a regular expression as a pattern.
procedure:
(publish url-wildcard-pattern (lambda (request) ...)) => undefined
procedure:(publish url-wildcard-pattern symbol) => undefined
This function is equivalent to
publish/wildcard
, and is present both for backwards compatibility and to offer a convenient shorthand.
procedure:
(unpublish url-pattern) => undefined
Removes a previously published procedure at the given pattern. The
url-pattern
passed tounpublish
must be identical to the one used to publish.
procedure:
(get-published url-pattern) => procedure/#f
Returns the procedure published at the given
url-pattern
or #f if none is found.
procedure:
(get-all-published) => alist
Returns an association list made of (
pattern
procedure
notation
) elements or '() if no procedures are published.
procedure:
(publish-bulk ((url-pattern [procedure|symbol] notation) ...)) => undefined
Given an association list of (
url-pattern
procedure
notation
), publishes all the given procedures or symbols to the provided patterns.Depending on whether
notation
is the symbol'wildcard
or'regexp
, the givenurl-pattern
should be either a wildcard or regular expression pattern.