10.1 Route context APIs ¶
(rc-path <route-context>)
- Get the requested path, that is to say, the actual URI visited by the client.
;; e.g
(get "/hello/world" (lambda (rc) (rc-path rc)))
;; visit localhost:3000/hello/world or from any port you specified
;; the result is "/hello/world".
(get "/hello/:who" (lambda (rc) (rc-path rc)))
;; visit localhost:3000/hello/world or from any port you specified
;; the result is "/hello/world".
(rc-req <route-context>)
- Get the current HTTP request wrapped in record-type. About HTTP request please see HTTP Request. It stores HTTP request of Guile.
(rc-body <route-context>)
- Get the current request body:
- For a regular HTTP request, the body should be a bytevector;
- For a Websocket request, the body should be Websocket frame as a record-type.
(rc-method <route-context>)
- Get the current requested HTTP method.
(rc-conn <route-context>)
- Get the current DB connection if you’ve requested one, please checkout DB shortcut.
(rc-qt <route-context>)
- Get query table, which is a key-value list parsed from query string.
(rc-handler <route-context>)
- Get the current request handler. The tricky part is that you can only get this handler within this handler unless you can go no where to run rc-handler correctly.
- It’s on your own risk to use this API. But now that we have powerful first class lambda, you may do some magic. Well, depends on you.
(rc-mtime <route-context>) ; getter
(rc-mtime! <route-context>) ; setter
- You may set it in the handler to return you customized modified time. For static pages, the mtime is set automatically. But sometimes people may want to set it in a dynamic generated page.
(rc-cookie <route-context>)
- The cookies parsed from request header.
(rc-set-cookie! <route-context>)
- Set response cookie from server side. If you want to return cookies to the client, please use it.
There’re other APIs in route-context, but they’re largely used for internals of Artanis, rarely useful for users. So we don’t list them here.