Route Requests with Ring
Web Development with Clojure, Third Edition — by Dmitri Sotnikov, Scot Brown (15 / 107)
👈 Chapter 2 Luminus Web Stack | TOC | Extend Ring 👉
Ring abstracts the details of HTTP into a concise and modular API that can be used as a base for any web application. If you’ve developed web applications in Python or Ruby, you’ll find it similar to the WSGI and Rack libraries found in those languages.[17][18] Ring has adapters for many popular HTTP servers. The most common choices are embedded HTTP servers such as Jetty or HTTP Kit.[19][20]
Since Ring is the de facto standard HTTP library, many mature web development tools and libraries are built on top of it. Even though you’ll rarely use Ring directly, it’s the backbone of Clojure web applications. Knowing how it works is crucial to understanding Clojure web development.
Ring applications consist of four basic components: the handler, the request, the response, and the middleware. When an HTTP request is received from the client via the HTTP server, it is transformed into a Ring request by the adapter. This request is passed down the middleware stack, being modified as necessary, until it reaches the handler. The handler generates a Ring response from the request. It’s then passed back up the middleware stack, being modified…