Skip to content

Instantly share code, notes, and snippets.

@minikomi
Last active December 25, 2015 20:49
Show Gist options
  • Save minikomi/7037813 to your computer and use it in GitHub Desktop.
Save minikomi/7037813 to your computer and use it in GitHub Desktop.
#lang racket
(require web-server/servlet-env
web-server/dispatch
web-server/http
web-server/http/bindings
web-server/formlets)
(define new-post-formlet
(formlet
(#%# ,{input-string . => . title}
,{input-string . => . body})
(values title body)))
(define (index req)
(response/xexpr
`(html (head (title "My Blog"))
(body
(h1 "My Blog")
(form ([action "/hand"] [method "POST"])
,@(formlet-display new-post-formlet)
(input ([type "submit"])))))))
(define (handler req)
(define-values (title body)
(formlet-process new-post-formlet req))
(response/xexpr
`(html (head (title "My Blog"))
(body
(h1 ,title)
(p ,body)))))
(define-values (main-dispatch main-url)
(dispatch-rules
[("hand") #:method "post" handler]
[("") #:method "get" index]
))
(serve/servlet
main-dispatch
#:port 8002
#:listen-ip #f
#:command-line? #t
#:servlet-regexp #rx""
#:servlet-path "/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment