chickadee » awful » define-page

(define-page path contents #!key css title doctype headers charset no-ajax use-ajax no-template no-session no-db no-javascript-compression method) procedure

Define an awful page.

path is the path to the page. It can be represented by two types: a string and a regular expression object.

If it is a string, the path used in the URI will be bound to the given no-argument procedure contents.

If it is a regular expression object, any request whose URL path matches the regular expression will be handled by the one-argument procedure contents. Both the regex egg and the irregex unit are supported. This procedure will be given the requested path.

method (a symbol or a list) indicates the HTTP method to be used (e.g., GET, POST, PUT). method can also be a list of methods. In this case, awful will define a page for each method of the list. Methods are case-insensitive. Pages that use different methods can use the same path.

The css, title, doctype, headers and charset keyword parameters have the same meaning as html-page (from the html-utils egg).

If no-ajax is #t, it means that the page won't use ajax, even if the enable-ajax parameter is #t.

If use-ajax is #t, it means that the page will be linked to the ajax library, even if the enable-ajax parameter is #f.

If no-template is #t, it means that no page template (see the page-template parameter) should be used.

If no-session is #t, it means that the page should not use session.

If no-db is #t, it means that the page should not use the database, even when database usage is activated by enable-db and db-credentials is not #f.

If no-javascript-compression is #t the javascript code for the page is not compressed, even when enable-javascript-compression is not #f.

Examples:

(use srfi-1 ;; for filter-map
     regex) ;; for regexp

;; http://host:port/foo => "bar"
(define-page "/foo"
  (lambda ()
    "bar"))

;; http://host:port/add/1/2/3 => 6
(define-page (regexp "/add/.*")
  (lambda (path)
    (let ((numbers (filter-map string->number (string-split path "/"))))
      (number->string (apply + numbers)))))