Middleware in Ring
Middleware in ring is a way to modify the incoming requests or outgoing responses.
Middleware can also wrap handlers or other middleware, affecting their behaviour. For example the
wrap-reload middleware enables live reloading by detecting file changes and reloading affected functions into their namespace, before the request is passed to the relevant handler function
Here is a list of middleware available in Ring itself:
ring/ring-core middleware includes:
- wrap-cookies (ring.middleware.cookies)
- wrap-file (ring.middleware.file)
- wrap-file-info (ring.middleware.file-info)
- wrap-flash (ring.middleware.flash)
- wrap-keyword-params (ring.middleware.keyword-params)
- wrap-multipart-params (ring.middleware.multipart-params
- wrap-nested-params (ring.middleware.nested-params
- wrap-params (ring.middleware.params)
- wrap-session (ring.middleware.session)
ring/ring-devel middleware provides:
- wrap-lint (ring.middleware.lint)
- wrap-reload (ring.middleware.reload)
- wrap-stacktrace (ring.middleware.stacktrace)
Templates can be used to create a project with a given set of dependencies as well as Clojure code.
There is a
compojure template that gives you a basic running web application. To use this template to create a new project use the following command, substituting your own project-name
lein new compojure project-name
This project contains ring and compojure. The dependency for ring is
ring/site-defaults which includes some sensible default settings for your application, eg security settings such as anti-forgery.
See the definition of ring/site-defaults for further information.