HoLy
(require HoLy) | package: HoLy |
HoLy is simple a HTTP-server Library for Racket.
Example of usage:
(require HoLy) (http/get "/" (λ (req) "Welcome")) (http/get "/article/:id" (λ (req) (let* ((id (request/param 'id))) (string-append "This is article #" id)))) (server/set-port 8080) (server/run)
1 http/get
Defines request handler for GET-request
(define (http/get path proc))
Where path is a path to resource(placeholder’s can be used, eg. "/" or "/posts/:category/:id").
2 http/post
Defines request hanlder for POST-request.
(define (http/post path proc))
Where path is a path to resource(placeholder’s can be used, eg. "/" or "/posts/:category/:id").
3 http/delete
Defines request hanlder for DELETE-request.
(define (http/delete path proc))
Where path is a path to resource(placeholder’s can be used, eg. "/" or "/posts/:category/:id").
4 http/put
Defines request hanlder for PUT-request.
(define (http/put path proc))
Where path is a path to resource(placeholder’s can be used, eg. "/" or "/posts/:category/:id").
5 request/param
Gets request parameter. It might be GET, POST or placeholder parameter
(define (request/param name))
6 request/cookie
Gets request cookie value by name.
(define (request/cookie name))
7 response/make
Prepares response(for defining custom http response code or setting headers).
(define (response/make #:code [code 200] #:message [message #"OK"] #:seconds [seconds (current-seconds)] #:mime-type [mime-type TEXT/HTML-MIME-TYPE] #:headers [headers (list (make-header #"Cache-Control" #"no-cache"))] content))
8 response/404
Responses with 404 status code
9 server/set-port
Defines port for server listening(by default it is 8000).
(define (server/set-port [port 8000]))
10 server/run
Runs server’s event loop.