Next: , Up: Basic concepts  

2.1 Middleware composition

The main utility of this package is the compose-middlewares macro. Thus, having all web-application’s functionality organized in a set of middleware procedures (probably router, as the most important one), the whole app, as a single request processing procedure, can be defined as (assuming some not-real middleware names, just to describe the idea):

(define app (compose-middlewares
              error-handler-middleware
              logger-middleware
              request-filter-middleware
              router-middleware)

The result of applying compose-middlewares to a set of procedures is a procedure of two arguments: a standard Guile (web request) object and a request body bytevector (or #f, if missing). The procedure returns, as it is expected by Guile’s web server, the two values: a standard (web response) object (or just an alist of response headers) and a response body. So, its obvious that one can just pass the composed procedure to run-server procedure.

(use-modules (web server))

(run-server app)

Next: , Up: Basic concepts