Peter Marklund

Peter Marklund's Home

2015-07-13

Clojure - a Ring www Redirect Middleware

Something I really appreciate with web development in Clojure is the Ring HTTP API and especially how requests and responses are associative data. This is of course a reflection of the data orientated nature of the Clojure language. It's also elegant how you can use the Clojure Thread first macro to chain middleware together. A middleware takes a Ring handler as its first argument plus any additional arguments that configure the handler and returns a new handler function. A Ring handler is a function that takes a request map and returns a response map. I guess you can't make it much simpler than that.

Here is an example of a simple www-redirect middleware: