about summary refs log tree commit diff stats
path: root/rnd/guile/play.scm
blob: 6307c099a50e768bfad60e850bf889a4e4e10f8f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
;;; Hello HTTP server
(use-modules 
  (web server)
  (web request)
  (web response)
  (web uri))

(define (request-path-components request)
  (split-and-decode-uri-path (uri-path (request-uri request))))

(define (routes-handler request body)
  (cond ((equal? (request-path-components request)
              '("banana"))
      (values '((content-type . (text/plain)))
              "banana kiwi apple pineapple watermelon grapefruit"))
        ((equal? (request-path-components request)
                 '("corn"))
         (values '((content-type . (text/plain)))
                 "corn oats millit wheat amaranth quinoa"))
      (not-found request)))

(define (not-found request)
  (values (build-response #:code 404)
          (string-append "Resource not found: "
                         (uri->string (request-uri request)))))


(run-server routes-handler)