parsing json body in spiffy added by d4 on Sun Jan 16 12:51:43 2022

(import srfi-1              
        (chicken io)        
        (chicken port)      
        sxml-serializer     
        medea               
        intarweb            
        uri-common          
        spiffy              
        spiffy-request-vars)

(define (handle-api path json)      
  `(html                              
     (body                            
       (h1 "Hello")                   
       (p ,(alist-ref 'yolo json))))) 
                                                                             
(define (send-sxml-response sxml)                                            
  ;; Function to serialize and send SXML as HTML                             
  (with-headers                                                              
    `((connection close))                                                    
    (lambda () (write-logged-response)))                                     
  (serialize-sxml                                                            
    sxml                                                                     
    output: (response-port (current-response))))                             
                                                                             
(define (handle-request continue)                                            
  (let* ((request (current-request))                                         
         (uri (request-uri request))                                         
         (path (uri-path uri))                                               
         (headers (request-headers request))                                 
         (body-lenght (header-value 'content-length headers))                
         (json-string (read-string body-lenght (request-port request)))      
         (json (with-input-from-string json-string read-json)))
    (print path)                                                             
    (print request)                                                          
    (print json)                                                             
    (send-sxml-response (handle-api path json))))        
                                                                             
(vhost-map `((".*" . ,handle-request)))                                      
(server-port 8080)                                                           
(start-server)