Skip to content

Instantly share code, notes, and snippets.

@arjunguha
Created March 19, 2014 13:39
Show Gist options
  • Select an option

  • Save arjunguha/9641831 to your computer and use it in GitHub Desktop.

Select an option

Save arjunguha/9641831 to your computer and use it in GitHub Desktop.
#lang racket
(require json
web-server/servlet
web-server/servlet-dispatch
web-server/web-server
web-server/dispatch)
(define-values (start mk-url)
(dispatch-rules
[("") index]
[("json") json]))
(define (index req)
(response/xexpr
`(html
(body
(h1 "Hello")))))
(define (json req)
(json-response #hash((studentId . 400))))
(define (json-response json)
(response
200 #"OK"
(current-seconds)
#"application/json"
empty
(λ (port)
(write-json json port))))
(serve #:dispatch (dispatch/servlet start)
#:port 8080)
@jcollard

Copy link
Copy Markdown

Wow! This is has a lot of stuff under the hood that was annoying in the version I wrote. Thanks for sharing this.

@jpolitz

jpolitz commented Mar 20, 2014

Copy link
Copy Markdown

Yeah sometimes it's not easy to find the right tutorial with Racket because they're so excited that they can do everything. This is probably a better tutorial: http://docs.racket-lang.org/continue/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment