8 Page: Short-hand for Common Patterns
|(require web-server/page)||package: web-server-lib|
The Web Server provides a simple utility library for building Web applications that consist mostly of send/suspend/dispatch-created pages and request handling.
(page e ...)
(page (response/xexpr `(html (body (a ([href ,(embed/url (λ (req) "You clicked!"))]) "Click me")))))
The binding interface of web-server/http is powerful, but subtle to use conveniently due to its protection against hostile clients.
(current-request req) → void? req : request?
(get-binding id [req #:format format])
→ (or/c false/c string? bytes? binding?) id : binding-id/c req : request? = (current-request) format : binding-format/c = 'string
(get-bindings id [req #:format format])
→ (listof (or/c string? bytes? binding?)) id : binding-id/c req : request? = (current-request) format : binding-format/c = 'string
They accept a form identifier (id) as either a byte string, a string, or a symbol. In each case, the user input is compared in a case-sensitive way with the form input.
Finally, they accept an optional keyword argument (format) that specifies the desired return format. The default, 'string, produces a UTF-8 string (or #f if the byte string cannot be converted to UTF-8.) The 'bytes format always produces the raw byte string. The 'file format produces the file upload content (or #f if the form input was not an uploaded file.) The 'binding format produces the binding object.