7.7
HoLy
Link to this document with
@other-doc['(lib "HoLy/scribblings/HoLy.scrbl")]
Link to this document with
@other-doc['(lib "HoLy/scribblings/HoLy.scrbl")]
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
Link to this section with
@secref["http_get" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Link to this section with
@secref["http_get" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Defines request handler for GET-request
Where path is a path to resource(placeholder’s can be used, eg. "/" or "/posts/:category/:id").
2 http/post
Link to this section with
@secref["http_post" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Link to this section with
@secref["http_post" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
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
Link to this section with
@secref["http_delete" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Link to this section with
@secref["http_delete" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
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
Link to this section with
@secref["http_put" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Link to this section with
@secref["http_put" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Defines request hanlder for PUT-request.
Where path is a path to resource(placeholder’s can be used, eg. "/" or "/posts/:category/:id").
5 request/param
Link to this section with
@secref["request_param" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Link to this section with
@secref["request_param" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Gets request parameter. It might be GET, POST or placeholder parameter
(define (request/param name))
6 request/cookie
Link to this section with
@secref["request_cookie" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Link to this section with
@secref["request_cookie" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Gets request cookie value by name.
(define (request/cookie name))
7 response/make
Link to this section with
@secref["response_make" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Link to this section with
@secref["response_make" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
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
Link to this section with
@secref["response_404" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Link to this section with
@secref["response_404" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Responses with 404 status code
9 server/set-port
Link to this section with
@secref["server_set-port" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Link to this section with
@secref["server_set-port" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Defines port for server listening(by default it is 8000).
(define (server/set-port [port 8000]))
10 server/run
Link to this section with
@secref["server_run" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Link to this section with
@secref["server_run" #:doc '(lib "HoLy/scribblings/HoLy.scrbl")]
Runs server’s event loop.