about summary refs log blame commit diff stats
path: root/rkt/bookmarks/server.rkt
blob: ae12dccefec26255fe5d2d4fecf64867bf009dc3 (plain) (tree)

























                                                                                   
#lang racket
(require web-server/http/xexpr
                 web-server/servlet
                 web-server/servlet-env)

(define (start request)
    (case (request-method request)
        [('GET) (handle-get request)]
        [('POST) (handle-post request)]
        [else (response/xexpr
                        `(html (body (p "Method not supported"))))]))

(define (handle-get request)
    (response/xexpr
     `(html (body (p "GET request received")))))

(define (handle-post request)
    (let* [(params (request-bindings request))
                 (data (extract-binding/single 'data params))]
        (response/xexpr
         `(html (body (p ,(format "POST request received with data: ~a" data)))))))

(serve/servlet start
                             #:port 8080
                             #:servlet-path "/api"
                             #:servlet-regexp #rx"")