Darren Holloway walks through the philosophy of Ring/Clojure

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

Darren Holloway has written a post that should be added to the wiki on Github where Ring is hosted. He covers all the stuff that had me the most confused when I started doing web development with Clojure. He offers easy examples in pseudo-code to get the basic ideas across. I wish every project on Github had an introductory tutorial written in this style.

An excerpt:

Ring Conceptually

Technically, Ring isn’t a framework or an application, but rather a specification on how HTTP requests are to be handled by some server. Because of this, you don’t actually need to run a webserver to explore ring.

Ring specifies that a Request is processed by a Handler and returns a Response. It also specifies that there may be some Middleware involved, but that just confuses the picture by making things more complex; let’s ignore that for now.

Taking away the Clojure’isms and functional programming concepts, this actually describes pretty much all web applications… Say you want to search for this page. You open your web browser and enter http://www.google.com into the location bar, and Google’s home search page comes up.

The Request was for the URL “/” on the server www.google.com using the HTTP protocol.
The Handler was something run by Google that understood that “/” was the “home page.”
The Response was the HTML and Javascript that is displayed in your browser.
In pseudo-functional-programming, from Google’s perspective, there were two handlers here:

One that knew that “/” was the home page, and
One that returned the home page
In terms from other frameworks, the first handler was the Controller or the Router, and the second was the View or Provider.

function any-google-page(request) # a router
if request.path == “/” then
call google-home-page(request)
else
call something-else(request)
end-if
end-function

function google-home-page(request) # a provider
return “200 OK” and html-for-google-home-page
end-function

Post external references

  1. 1
    http://fhf.org/archives/739
Source