source: project/wiki/eggref/4/spiffy-uri-match @ 27088

Last change on this file since 27088 was 27088, checked in by andyjpb, 9 years ago

Explain how to integrate with spiffy.

File size: 1.9 KB
Line 
1[[tags: egg]]
2
3== spiffy-uri-match
4
5[[toc:]]
6
7=== Description
8
9A library providing integration of [[uri-match]] for [[spiffy]].
10
11=== Author
12
13Moritz Heidkamp
14
15=== Requirements
16
17Requires the [[uri-match]], [[spiffy]], [[uri-common]] and
18[[intarweb]] extensions.
19
20=== Documentation
21
22<procedure>(uri-match/spiffy routes)</procedure>
23
24Returns a procedure suitable for use as a spiffy handler. It will
25match against the HTTP method and URI of the {{current-request}}
26parameter. The {{routes}} argument is passed directly to
27{{make-uri-matcher}} of [[uri-match]] and thus must be in the format
28described there. If a route matches, its handler is called with
29{{current-response}} modified to include the headers given in the
30{{default-response-headers}} parameter. If no route matches, the
31handler will call the {{continue}} procedure passed by spiffy.
32
33[[uri-match/spiffy]] integrates with spiffy via the vhost-map hooks.
34
35<enscript highlight="scheme">
36(vhost-map `((".*" . ,(lambda (continue) (continue)))))
37(vhost-map `((".*" . ,(lambda (c) (send-status 200 "TEST")))))
38(vhost-map `((".*" . ,(uri-match/spiffy `(((/ "") (GET ,(lambda (c) (c)))))))))
39(vhost-map `((".*" . ,(uri-match/spiffy `(((/ "") (GET ,(lambda (c) (send-status 200 "TEST")))))))))
40(vhost-map `((".*" . ,(uri-match/spiffy `(((/ "") (GET ,(lambda (c) (send-response
41                                                                     code: 200
42                                                                     reason: "OK"
43                                                                     body: "Hello World!"
44                                                                     headers: '((content-type text/html)))))))))))
45</enscript>
46
47
48<parameter>(default-response-headers [headers])</parameter>
49
50A list of headers to be used for all requests handled by handlers
51created through {{uri-match/spiffy}}. Defaults to
52
53  '((content-type #(text/html ((charset . "utf-8"))))
54    (accept-charset utf-8))
55
56<procedure>(redirect-to path #!key (code 302) (headers '()))</procedure>
57
58Convenience procedure for sending redirects relative to the current
59{{server-root-uri}}.
Note: See TracBrowser for help on using the repository browser.