WebGate

Check-in [e9f3970674]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:added an example for suspensions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e9f3970674c14a09e69bf726aaa5118303af66fa
User & Date: murphy 2011-09-23 21:26:50
Context
2011-09-25
01:51
suspended resource and error handling tweaks check-in: e657ff967b user: murphy tags: trunk
2011-09-23
21:26
added an example for suspensions check-in: e9f3970674 user: murphy tags: trunk
21:24
included an explicit return in the request handler continuation check-in: 7b68b3ded9 user: murphy tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to example.scm.

25
26
27
28
29
30
31









32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49




50
51
52
53
54
55
56
...
183
184
185
186
187
188
189














































































190

(require-library
 webgate)

(import
 webgate (only webgate-utils uri-encode))










(define-resource (root parameters)
  (make-html-response
   200
   `(html
     (head
      (meta ((charset "utf-8")))
      (title "WebGate")
      (meta ((name "description") (content "CHICKEN WebGate example")))
      (meta ((name "author") (content "Thomas Chust")))
      (link ((rel "stylesheet") (href "http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css"))))
     (body
      (div
       ((class "topbar"))
       (div
	((class "fill"))
	(div
	 ((class "container"))
	 (a ((class "brand") (href "#")) "WebGate"))))




      (div
       ((class "container"))
       (div
	((class "hero-unit"))
	(h1 "Application Example")
	(p "This sample program just shows some information extracted from the incoming request."))
       (div
................................................................................
	   (div
	    ((class "actions"))
	    (input ((type "submit") (class "btn primary") (value "Submit")))
	    nbsp
	    (input ((type "reset") (class "btn") (value "Reset"))))))))
       (footer copy "2011 by Thomas Chust"))))))















































































(webgate-main)







>
>
>
>
>
>
>
>
>




|
<
<
<
<
<







|
>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45





46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
...
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

(require-library
 webgate)

(import
 webgate (only webgate-utils uri-encode))

(define common-head
  '(head
    (meta ((charset "utf-8")))
    (title "WebGate")
    (meta ((name "description") (content "CHICKEN WebGate example")))
    (meta ((name "author") (content "Thomas Chust")))
    (link ((rel "stylesheet") (href "http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css")))
    (style ((type "text/css")) "body{padding-top:60px}")))

(define-resource (root parameters)
  (make-html-response
   200
   `(html
     ,common-head





     (body
      (div
       ((class "topbar"))
       (div
	((class "fill"))
	(div
	 ((class "container"))
	 (a ((class "brand") (href "#")) "WebGate")
	 (ul
	  ((class "nav"))
	  (li ((class "active")) (a ((href "#")) "Miscellaneous"))
	  (li (a ((href ,(resource-uri calc "add"))) "Suspensions"))))))
      (div
       ((class "container"))
       (div
	((class "hero-unit"))
	(h1 "Application Example")
	(p "This sample program just shows some information extracted from the incoming request."))
       (div
................................................................................
	   (div
	    ((class "actions"))
	    (input ((type "submit") (class "btn primary") (value "Submit")))
	    nbsp
	    (input ((type "reset") (class "btn") (value "Reset"))))))))
       (footer copy "2011 by Thomas Chust"))))))

(define (numeric-parameter parameters key)
  (cond
   ((hash-table-ref/default parameters key #f)
    => (lambda (msgs)
	 (and (not (null? msgs))
	      (string->number (message-body (car msgs))))))
   (else
    #f)))

(define-resource (calc "calc" op parameters)
  (if (string=? op "add")
      (let* ((common-topbar
	      `(div
		((class "topbar"))
		(div
		 ((class "fill"))
		 (div
		  ((class "container"))
		  (a ((class "brand") (href "#")) "WebGate")
		  (ul
		   ((class "nav"))
		   (li (a ((href ,(resource-uri root))) "Miscellaneous"))
		   (li ((class "active")) (a ((href "#")) "Suspensions")))))))
	     (parameters
	      (send/suspend
	       (lambda (resume-uri)
		 (make-html-response
		  200
		  `(html
		    ,common-head
		    (body
		     ,common-topbar
		     (div
		      ((class "container"))
		      (form
		       ((method "GET") (action ,resume-uri))
		       (fieldset
			(legend "Add Numbers")
			(div
			 ((class "clearfix"))
			 (label ((for "a")) "First Summand")
			 (div
			  ((class "input"))
			  (input ((type "text") (id "a") (class "medium")
				  (name "a") (size "30")))))
			(div
			 ((class "clearfix"))
			 (label ((for "a")) "Second Summand")
			 (div
			  ((class "input"))
			  (input ((type "text") (id "b") (class "medium")
				  (name "b") (size "30")))))
			(div
			 ((class "actions"))
			 (input ((type "submit") (class "btn primary")
				 (value "Submit")))
			 nbsp
			 (input ((type "reset") (class "btn")
				 (value "Reset")))))))))))))
	     (a
	      (or (numeric-parameter parameters "a") 0))
	     (b
	      (or (numeric-parameter parameters "b") 0)))
	(make-html-response
	 200
	 `(html
	   ,common-head
	   (body
	    ,common-topbar
	    (div
	     ((class "container"))
	     (div
	      ((class "hero-unit"))
	      (h1 ,(number->string (+ a b)))
	      (p hellip "is the answer")))))))
      (make-error-response
       400 "Don't know how to perform the requested calculation.")))

(webgate-main)