diff options
Diffstat (limited to 'rkt/bookmarks/server.rkt')
-rw-r--r-- | rkt/bookmarks/server.rkt | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/rkt/bookmarks/server.rkt b/rkt/bookmarks/server.rkt new file mode 100644 index 0000000..ae12dcc --- /dev/null +++ b/rkt/bookmarks/server.rkt @@ -0,0 +1,26 @@ +#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"") \ No newline at end of file |