(sigil web)
(sigil web) - Web Application Framework
High-level API for building web applications with Sigil. Re-exports commonly used functionality from sub-modules.
For specialized access, import sub-modules directly: (sigil web routes) - Path-based routing (sigil web static) - Static file serving (sigil web middleware) - Middleware composition (sigil web cookies) - Cookie handling (sigil web ui) - Server-driven hypermedia components
Example: (import (sigil web) (sigil http))
(define app (-> (routes (router (route GET "/" home-handler) (route GET "/api/:id" api-handler) (route ANY "/static/*path" static-handler))) (with-logging) (with-not-found)))
(http-serve app port: 8080)
Exports
GETvariableRe-exported from (sigil web routes)
POSTvariableRe-exported from (sigil web routes)
PUTvariableRe-exported from (sigil web routes)
DELETEvariableRe-exported from (sigil web routes)
PATCHvariableRe-exported from (sigil web routes)
OPTIONSvariableRe-exported from (sigil web routes)
HEADvariableRe-exported from (sigil web routes)
ANYvariableRe-exported from (sigil web routes)
routeprocedureA route consists of a method, pattern, and handler
Re-exported from (sigil web routes)
route-methodprocedureGet the method field of a route struct.
Re-exported from (sigil web routes)
route-patternprocedureGet the pattern field of a route struct.
Re-exported from (sigil web routes)
route-handlerprocedureGet the handler field of a route struct.
Re-exported from (sigil web routes)
routerprocedureConvenience macro-like function for creating routers Usage: (router (route 'GET "/" handler1) (route 'POST "/api" handler2))
Re-exported from (sigil web routes)
make-routerprocedureCreate a router from a list of routes Returns a handler function: (request) -> response or #f
Re-exported from (sigil web routes)
path-paramprocedureGet a path parameter from request Returns value or #f if not found
Re-exported from (sigil web routes)
path-paramsprocedureGet all path parameters from request
Re-exported from (sigil web routes)
routesprocedureCombine multiple handlers into a single handler.
Returns the first non-#f response. Use with the threading macro to build middleware chains:
(-> (routes api-routes page-routes static-handler)
(with-logging)
(with-not-found))Re-exported from (sigil web routes)
make-static-handlerprocedureCreate a static file handler for a directory base-dir: root directory for static files options: optional alist with:
- index: index file name (default: "index.html")
- prefix: URL prefix to strip (default: "")
Re-exported from (sigil web static)
serve-fileprocedureServe a single file with appropriate headers Returns http-response or #f if file doesn't exist
Re-exported from (sigil web static)
safe-path?procedureCheck if a path is safe (no directory traversal) Returns #t if path doesn't contain dangerous components
Re-exported from (sigil web static)
wrap-middlewareprocedureWrap a handler with multiple middleware Middleware are applied right-to-left (last middleware is outermost) Each middleware is: (handler) -> new-handler
Re-exported from (sigil web middleware)
compose-middlewareprocedureCompose multiple middleware into one Returns a single middleware function
Re-exported from (sigil web middleware)
logger-middlewareprocedureLog requests and responses Options:
- output: port to write to (default: current-output-port)
Re-exported from (sigil web middleware)
cors-middlewareprocedureAdd CORS headers to responses origins: list of allowed origins, or '("*") for any
Re-exported from (sigil web middleware)
content-type-middlewareprocedureSet default Content-Type if not present
Re-exported from (sigil web middleware)
not-found-middlewareprocedureReturn 404 response if handler returns #f
Re-exported from (sigil web middleware)
with-loggingvariableWrap handler with request/response logging Keywords: output: - port for log output (default: current-output-port)
Re-exported from (sigil web middleware)
with-corsvariableWrap handler with CORS headers Keywords: allow-origin: - allowed origin ("" for any, default: "") allow-methods: - allowed methods string allow-headers: - allowed headers string
Re-exported from (sigil web middleware)
with-content-typevariableWrap handler with default Content-Type Keywords: default: - default content type (default: "text/html")
Re-exported from (sigil web middleware)
with-not-foundvariableWrap handler with 404 fallback Keywords: body: - custom 404 body HTML
Re-exported from (sigil web middleware)
parse-cookiesprocedureParse Cookie header into a dict with string keys. "name1=value1; name2=value2" -> #{"name1": "value1" "name2": "value2"}
Re-exported from (sigil web cookies)
cookie-refprocedureGet a specific cookie value from request.
Re-exported from (sigil web cookies)
cookiesprocedureGet all cookies from request as a dict.
Re-exported from (sigil web cookies)
set-cookieprocedureAdd Set-Cookie header to response Returns new response with cookie header added
Re-exported from (sigil web cookies)
delete-cookieprocedureDelete a cookie by setting it with max-age=0
Re-exported from (sigil web cookies)
build-set-cookie-headerprocedureBuild Set-Cookie header value name: cookie name value: cookie value options: alist with optional attributes:
- path: cookie path (default "/")
- domain: cookie domain
- max-age: seconds until expiration
- expires: expiration date string
- secure: boolean, only send over HTTPS
- http-only: boolean, not accessible via JavaScript
- same-site: "Strict", "Lax", or "None"
Re-exported from (sigil web cookies)