sigildocs

(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

GETvariable

Re-exported from (sigil web routes)

POSTvariable

Re-exported from (sigil web routes)

PUTvariable

Re-exported from (sigil web routes)

DELETEvariable

Re-exported from (sigil web routes)

PATCHvariable

Re-exported from (sigil web routes)

OPTIONSvariable

Re-exported from (sigil web routes)

ANYvariable

Re-exported from (sigil web routes)

routeprocedure

A route consists of a method, pattern, and handler

Re-exported from (sigil web routes)

route-methodprocedure

Get the method field of a route struct.

Re-exported from (sigil web routes)

route-patternprocedure

Get the pattern field of a route struct.

Re-exported from (sigil web routes)

route-handlerprocedure

Get the handler field of a route struct.

Re-exported from (sigil web routes)

routerprocedure

Convenience macro-like function for creating routers Usage: (router (route 'GET "/" handler1) (route 'POST "/api" handler2))

Re-exported from (sigil web routes)

make-routerprocedure

Create a router from a list of routes Returns a handler function: (request) -> response or #f

Re-exported from (sigil web routes)

path-paramprocedure

Get a path parameter from request Returns value or #f if not found

Re-exported from (sigil web routes)

path-paramsprocedure

Get all path parameters from request

Re-exported from (sigil web routes)

routesprocedure

Combine 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)

Create 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-fileprocedure

Serve a single file with appropriate headers Returns http-response or #f if file doesn't exist

Re-exported from (sigil web static)

safe-path?procedure

Check if a path is safe (no directory traversal) Returns #t if path doesn't contain dangerous components

Re-exported from (sigil web static)

Wrap 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 multiple middleware into one Returns a single middleware function

Re-exported from (sigil web middleware)

Log requests and responses Options:

  • output: port to write to (default: current-output-port)

Re-exported from (sigil web middleware)

Add CORS headers to responses origins: list of allowed origins, or '("*") for any

Re-exported from (sigil web middleware)

Set default Content-Type if not present

Re-exported from (sigil web middleware)

Return 404 response if handler returns #f

Re-exported from (sigil web middleware)

with-loggingvariable

Wrap handler with request/response logging Keywords: output: - port for log output (default: current-output-port)

Re-exported from (sigil web middleware)

with-corsvariable

Wrap 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)

Wrap handler with default Content-Type Keywords: default: - default content type (default: "text/html")

Re-exported from (sigil web middleware)

Wrap handler with 404 fallback Keywords: body: - custom 404 body HTML

Re-exported from (sigil web middleware)

parse-cookiesprocedure

Parse Cookie header into a dict with string keys. "name1=value1; name2=value2" -> #{"name1": "value1" "name2": "value2"}

Re-exported from (sigil web cookies)

cookiesprocedure

Get all cookies from request as a dict.

Re-exported from (sigil web cookies)